Count Vowel Substrings of a String LeetCode solution in JavaScript

1
/**
2
* @param {string} word
3
* @return {number}
4
*/
5
var isVowel = function (c) {
6
return c === "a" || c === "e" || c === "i" || c === "o" || c === "u";
7
};
8

9
var countVowelSubstrings = function (word) {
10
let vowelMap = new Map();
11
let total = 0;
12
let totalLen = word.length - 1;
13
for (let i = 0; i <= totalLen; i++) {
14
vowelMap.clear();
15
for (let j = i; j <= totalLen && isVowel(word[j]); j++) {
16
vowelMap.set(word[j], (vowelMap.get(word[j]) ?? 0) + 1);
17
if (vowelMap.size == 5) total++;
18
}
19
}
20
return total;
21
};

0

WPM •0 •0

100%

ACC •0 •0

0s

TIME •0