Skip to content

Commit

Permalink
Time: 8 ms (48.29%), Space: 85.7 MB (76.77%) - LeetHub
Browse files Browse the repository at this point in the history
  • Loading branch information
Amit-S-Sahu committed Jan 2, 2025
1 parent 9d31b88 commit c75e9a5
Showing 1 changed file with 28 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
class Solution {
public int[] vowelStrings(String[] words, int[][] queries) {
int arr[] = new int[words.length];

HashSet<Character> set = new HashSet();
set.add('a');
set.add('e');
set.add('i');
set.add('o');
set.add('u');

for (int i = 0; i < words.length; i++){
String s = words[i];
if (set.contains(s.charAt(0)) && set.contains(s.charAt(s.length() - 1))) arr[i] = i > 0 ? arr[i - 1] + 1 : 1;
else arr[i] = i > 0 ? arr[i - 1] : 0;
}
int ans[] = new int[queries.length];
int i = 0;
for(int q[] : queries){
int l = q[0];
int j = q[1];
int k = arr[j];
k = l == 0 ? k : k - arr[l - 1];
ans[i++] = k;
}
return ans;
}
}

0 comments on commit c75e9a5

Please sign in to comment.