Skip to content

Commit 8e571f7

Browse files
authored
Create 2062-count-vowel-substrings-of-a-string.js
1 parent 4564605 commit 8e571f7

File tree

1 file changed

+27
-0
lines changed

1 file changed

+27
-0
lines changed
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
/**
2+
* @param {string} word
3+
* @return {number}
4+
*/
5+
const countVowelSubstrings = function(word) {
6+
let res = 0, n= word.length
7+
for(let i = 0; i < n - 1;i++) {
8+
for(let j = i + 1;j < n; j++) {
9+
if(valid(word, i, j)) res++
10+
}
11+
}
12+
13+
return res
14+
15+
function valid(s, i, j) {
16+
const set = new Set(['a', 'e', 'i', 'o','u'])
17+
const vis = new Set()
18+
for(let idx = i; idx <= j; idx++) {
19+
if(!set.has(s[idx])) return false
20+
else {
21+
vis.add(s[idx])
22+
}
23+
}
24+
// console.log(vis)
25+
return vis.size === 5
26+
}
27+
};

0 commit comments

Comments
 (0)