-
Notifications
You must be signed in to change notification settings - Fork 0
/
Goat Latin
30 lines (25 loc) · 834 Bytes
/
Goat Latin
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
class Solution {
public String toGoatLatin(String S) {
String[] words=S.split(" ");
StringBuilder res = new StringBuilder();
for(int i = 0; i < words.length; i++){
res.append(process(words[i]));
for(int j = 0; j < i + 1; j++)
res.append("a");
if(i != words.length - 1)
res.append(" ");
}
return res.toString();
}
public String process(String word) {
if(isVowel(word.charAt(0))) {
return word + "ma";
} else {
return word.substring(1) + word.charAt(0) + "ma";
}
}
public boolean isVowel(char c) {
return c == 'a' || c == 'A' || c == 'e' || c == 'E' || c == 'i' || c == 'I' || c == 'o' || c == 'O' || c == 'u' || c == 'U';
}
}
#Status: Solved