Skip to content

Commit 24b7a6a

Browse files
add 2559
1 parent 32a2cb7 commit 24b7a6a

File tree

2 files changed

+47
-0
lines changed

2 files changed

+47
-0
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ _If you like this project, please leave me a star._ ★
88

99
| # | Title | Solutions | Video | Difficulty | Tag
1010
|------|----------------|------------------------------------------------------------------------------------------------------------------------------------------|------------------------------------------------------------------------------|----------------------------------|-------------
11+
| 2559 |[Count Vowel Strings in Ranges](https://leetcode.com/problems/count-vowel-strings-in-ranges/)| [Java](../master/src/main/java/com/fishercoder/solutions/_2559.java) | | Medium |
1112
| 2558 |[Take Gifts From the Richest Pile](https://leetcode.com/problems/take-gifts-from-the-richest-pile/)| [Java](../master/src/main/java/com/fishercoder/solutions/_2558.java) | | Easy |
1213
| 2554 |[Maximum Number of Integers to Choose From a Range I](https://leetcode.com/problems/maximum-number-of-integers-to-choose-from-a-range-i/)| [Java](../master/src/main/java/com/fishercoder/solutions/_2554.java) | | Medium |
1314
| 2553 |[Separate the Digits in an Array](https://leetcode.com/problems/separate-the-digits-in-an-array/)| [Java](../master/src/main/java/com/fishercoder/solutions/_2553.java) | | Easy |
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
package com.fishercoder.solutions;
2+
3+
import java.util.Arrays;
4+
import java.util.HashSet;
5+
import java.util.Set;
6+
7+
public class _2559 {
8+
public static class Solution1 {
9+
public int[] vowelStrings(String[] words, int[][] queries) {
10+
int[] ans = new int[queries.length];
11+
boolean[] vowels = new boolean[words.length];
12+
Set<Character> set = new HashSet<>(Arrays.asList('a', 'e', 'i', 'o', 'u'));
13+
int i = 0;
14+
for (String word : words) {
15+
if (word.length() == 1) {
16+
if (set.contains(word.charAt(0))) {
17+
vowels[i] = true;
18+
}
19+
} else if (set.contains(word.charAt(0)) && set.contains(word.charAt(word.length() - 1))) {
20+
vowels[i] = true;
21+
}
22+
i++;
23+
}
24+
int[] preSums = new int[words.length];
25+
preSums[0] = vowels[0] == true ? 1 : 0;
26+
for (int k = 1; k < words.length; k++) {
27+
if (vowels[k]) {
28+
preSums[k] = preSums[k - 1] + 1;
29+
} else {
30+
preSums[k] = preSums[k - 1];
31+
}
32+
}
33+
i = 0;
34+
for (int[] query : queries) {
35+
int start = query[0];
36+
int end = query[1];
37+
if (start == 0) {
38+
ans[i++] = preSums[end];
39+
} else {
40+
ans[i++] = preSums[end] - preSums[start - 1];
41+
}
42+
}
43+
return ans;
44+
}
45+
}
46+
}

0 commit comments

Comments
 (0)