-
Notifications
You must be signed in to change notification settings - Fork 1
/
CountVowelSubstringsOfAString.java
52 lines (48 loc) · 1.52 KB
/
CountVowelSubstringsOfAString.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
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
package com.smlnskgmail.jaman.leetcodejava.easy;
// https://leetcode.com/problems/count-vowel-substrings-of-a-string/
public class CountVowelSubstringsOfAString {
private final String input;
public CountVowelSubstringsOfAString(String input) {
this.input = input;
}
public int solution() {
int length = input.length();
if (length < 5) {
return 0;
}
int[] vowels = new int[128];
vowels['a'] = 1;
vowels['e'] = 1;
vowels['i'] = 1;
vowels['o'] = 1;
vowels['u'] = 1;
int result = 0;
for (int i = 0; i < length; i++) {
int[] chars = new int[128];
for (int j = i + 5; j <= length; j++) {
boolean onlyVowels = true;
for (int k = i; k < j; k++) {
char c = input.charAt(k);
if (vowels[c] == 1) {
chars[input.charAt(k)] = 1;
} else {
onlyVowels = false;
break;
}
}
if (onlyVowels) {
if (chars['a'] == 1
&& chars['e'] == 1
&& chars['i'] == 1
&& chars['o'] == 1
&& chars['u'] == 1) {
result++;
}
} else {
break;
}
}
}
return result;
}
}