-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Time: 8 ms (48.29%), Space: 85.7 MB (76.77%) - LeetHub
- Loading branch information
1 parent
9d31b88
commit c75e9a5
Showing
1 changed file
with
28 additions
and
0 deletions.
There are no files selected for viewing
28 changes: 28 additions & 0 deletions
28
2559-count-vowel-strings-in-ranges/2559-count-vowel-strings-in-ranges.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
} |