forked from fishercoder1534/Leetcode
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path_2062.java
32 lines (30 loc) · 1.06 KB
/
_2062.java
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
29
30
31
32
package com.fishercoder.solutions;
import java.util.Arrays;
import java.util.HashSet;
import java.util.Set;
public class _2062 {
public static class Solution1 {
public int countVowelSubstrings(String word) {
int count = 0;
Set<Character> vowels = new HashSet<>(Arrays.asList('a', 'e', 'i', 'o', 'u'));
Set<Character> window = new HashSet<>();
for (int i = 0; i < word.length(); i++) {
window.clear();
if (vowels.contains(word.charAt(i))) {
window.add(word.charAt(i));
for (int j = i + 1; j < word.length(); j++) {
if (!vowels.contains(word.charAt(j))) {
break;
} else {
window.add(word.charAt(j));
if (window.size() == 5) {
count++;
}
}
}
}
}
return count;
}
}
}