-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathJan2 2025 DC
25 lines (25 loc) · 887 Bytes
/
Jan2 2025 DC
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
2559. Count Vowel Strings in Ranges
class Solution {
public int[] vowelStrings(String[] words, int[][] queries) {
int n=words.length;
int m=queries.length;
int[] ans=new int[m];
Set<Character> set=new HashSet<>(Arrays.asList('a', 'e', 'i', 'o', 'u'));;
int[] sum=new int[n];
sum[0]=( set.contains(words[0].charAt(0)) && set.contains(words[0].charAt(words[0].length()-1)) )?1:0;
for(int i=1; i<n; i++){
if( set.contains(words[i].charAt(0)) && set.contains(words[i].charAt(words[i].length()-1)) ){
sum[i]=sum[i-1]+1;
}
else{
sum[i]=sum[i-1];
}
}
int prev=0;
for(int i=0; i<m; i++){
prev=queries[i][0]-1<0?0:sum[queries[i][0]-1];
ans[i]=sum[queries[i][1]] - prev;
}
return ans;
}
}