-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathjan2.java
More file actions
28 lines (28 loc) · 912 Bytes
/
jan2.java
File metadata and controls
28 lines (28 loc) · 912 Bytes
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
26
27
28
class Solution {
public int[] vowelStrings(String[] words, int[][] queries) {
Set<Character> vowels=new HashSet<>();
vowels.add('a');
vowels.add('e');
vowels.add('i');
vowels.add('o');
vowels.add('u');
int[] prefixSum=new int[words.length+1];
int[] result=new int[queries.length];
for(int i=0;i<words.length;i++){
String word=words[i];
if(vowels.contains(word.charAt(0)) && vowels.contains(word.charAt(word.length()-1))){
prefixSum[i+1]=prefixSum[i]+1;
}
else{
prefixSum[i+1]=prefixSum[i];
}
}
int index=0;
for(int[] query:queries){
int leftRange=query[0];
int rightRange=query[1];
result[index++]=prefixSum[rightRange+1]-prefixSum[leftRange];
}
return result;
}
}