Skip to content

Commit c3b993d

Browse files
authored
Create Goat Latin
1 parent 911f8c8 commit c3b993d

File tree

1 file changed

+22
-0
lines changed

1 file changed

+22
-0
lines changed

Goat Latin

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
class Solution {
2+
public String toGoatLatin(String S) {
3+
String[] words = S.split(" ");
4+
String res = "";
5+
for(int i = 0; i<words.length; i++){
6+
String existing = words[i];
7+
String temp = existing.toLowerCase();
8+
char f = temp.charAt(0);
9+
if(f == 'a' || f == 'i' || f == 'e' || f == 'o' || f == 'u'){
10+
existing += "ma";
11+
}
12+
else{
13+
existing = existing.substring(1, existing.length()) + existing.charAt(0) + "ma";
14+
}
15+
for(int j = -1; j<i; j++){
16+
existing+="a";
17+
}
18+
res += existing + " ";
19+
}
20+
return res.substring(0, res.length()-1);
21+
}
22+
}

0 commit comments

Comments
 (0)