Skip to content

Commit 976058a

Browse files
authored
Create 2559-count-vowel-strings-in-ranges.js
1 parent 8b459b2 commit 976058a

File tree

1 file changed

+27
-0
lines changed

1 file changed

+27
-0
lines changed

2559-count-vowel-strings-in-ranges.js

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
/**
2+
* @param {string[]} words
3+
* @param {number[][]} queries
4+
* @return {number[]}
5+
*/
6+
const vowelStrings = function(words, queries) {
7+
const n = words.length
8+
const pre = Array(n + 1).fill(0)
9+
const set = new Set(['a', 'e', 'i', 'o', 'u'])
10+
for(let i = 0; i < n; i++) {
11+
const cur = words[i]
12+
if(set.has(cur[0]) && set.has(cur[cur.length - 1])) pre[i + 1] = 1
13+
}
14+
15+
const cnt = Array(n + 1).fill(0)
16+
for(let i = 1; i <= n; i++) {
17+
cnt[i] = cnt[i - 1] + pre[i]
18+
}
19+
20+
const res = []
21+
22+
for(const [l, r] of queries) {
23+
res.push(cnt[r + 1] - cnt[l])
24+
}
25+
26+
return res
27+
};

0 commit comments

Comments
 (0)