Skip to content

Commit 4564605

Browse files
authored
Create 2063-vowels-of-all-substrings.js
1 parent 7c0abb6 commit 4564605

File tree

1 file changed

+20
-0
lines changed

1 file changed

+20
-0
lines changed

2063-vowels-of-all-substrings.js

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
/**
2+
* @param {string} word
3+
* @return {number}
4+
*/
5+
const countVowels = function(word) {
6+
let res = 0n
7+
const n = BigInt(word.length)
8+
const set = new Set(['a', 'e', 'i', 'o', 'u'])
9+
const dp = Array(n + 1n).fill(0n)
10+
for(let i = 0n; i < n; i++) {
11+
const ch = word[i]
12+
if(set.has(ch)) dp[i + 1n] = dp[i] + (i + 1n)
13+
else dp[i + 1n] = dp[i]
14+
}
15+
16+
for(const e of dp) res += e
17+
return res
18+
};
19+
20+

0 commit comments

Comments
 (0)