-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSolution.java
More file actions
55 lines (38 loc) · 1.21 KB
/
Solution.java
File metadata and controls
55 lines (38 loc) · 1.21 KB
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
53
54
55
package leetcode.vowelsGameInAString;
class Solution {
public boolean doesAliceWinMaisRapido(String s){
for(int i = 0; i < s.length(); i++){
char c = s.charAt(i);
switch (c){
case 'a', 'e', 'i', 'o', 'u': return true;
}
}
return false;
}
public boolean doesAliceWin(String s) {
return doesAliceWinRecursive(s, 0);
}
public boolean doesAliceWinRecursive(String s, int turnOf){
if(s == null) return checkWhoWons(turnOf);
int n = s.length();
int qtdVogals = 0;
for(int i = 0; i < n; i++){
char c = s.charAt(i);
if(isVogal(c)){
qtdVogals++;
if(turnOf == 1 && qtdVogals % 2 == 0){
return doesAliceWinRecursive(s.substring(i, n), 0);
} else if(turnOf == 0 && qtdVogals % 2 != 0){
return doesAliceWinRecursive(s.substring(i, n), 1);
}
}
}
return checkWhoWons(turnOf);
}
public boolean checkWhoWons(int turnOf){
return turnOf == 1;
}
public boolean isVogal(char c){
return "aeiou".indexOf(c) != -1;
}
}