Skip to content

Commit 72d8cf6

Browse files
solves #2586: Count the Number of Vowel Strings in Range in java
1 parent b29755c commit 72d8cf6

File tree

2 files changed

+28
-1
lines changed

2 files changed

+28
-1
lines changed

README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -806,7 +806,7 @@
806806
| 2574 | [Left and Right Sum Differences](https://leetcode.com/problems/left-and-right-sum-differences) | [![Java](assets/java.png)](src/LeftAndRightSumDifferences.java) | |
807807
| 2578 | [Split With Minimum Sum](https://leetcode.com/problems/split-with-minimum-sum) | [![Java](assets/java.png)](src/SplitWithMinimumSum.java) | |
808808
| 2582 | [Pass the Pillow](https://leetcode.com/problems/pass-the-pillow) | [![Java](assets/java.png)](src/PassThePillow.java) | |
809-
| 2586 | [Count the Number of Vowel Strings in Range](https://leetcode.com/problems/count-the-number-of-vowel-strings-in-range) | | |
809+
| 2586 | [Count the Number of Vowel Strings in Range](https://leetcode.com/problems/count-the-number-of-vowel-strings-in-range) | [![Java](assets/java.png)](src/CountTheNumberOfVowelStringsInRange.java) | |
810810
| 2591 | [Distribute Money to Maximum Children](https://leetcode.com/problems/distribute-money-to-maximum-children) | | |
811811
| 2595 | [Number of Even and Odd Bits](https://leetcode.com/problems/number-of-even-and-odd-bits) | | |
812812
| 2600 | [K Items With the Maximum Sum](https://leetcode.com/problems/k-items-with-the-maximum-sum) | | |
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
// https://leetcode.com/problems/count-the-number-of-vowel-strings-in-range
2+
// T: O(N)
3+
// S: O(1)
4+
5+
import java.util.Set;
6+
7+
public class CountTheNumberOfVowelStringsInRange {
8+
private final static Set<Character> VOWELS = Set.of('a', 'e', 'i', 'o', 'u');
9+
10+
public int vowelStrings(String[] words, int left, int right) {
11+
int vowelStrings = 0;
12+
for (int i = left ; i <= right ; i++) {
13+
if (isVowelString(words[i])) {
14+
vowelStrings++;
15+
}
16+
}
17+
return vowelStrings;
18+
}
19+
20+
private boolean isVowelString(String word) {
21+
return isVowel(word.charAt(0)) && isVowel(word.charAt(word.length() - 1));
22+
}
23+
24+
private boolean isVowel(char c) {
25+
return VOWELS.contains(c);
26+
}
27+
}

0 commit comments

Comments
 (0)