-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathGoatLatin.java
More file actions
34 lines (23 loc) 路 970 Bytes
/
Copy pathGoatLatin.java
File metadata and controls
34 lines (23 loc) 路 970 Bytes
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
class Solution {
public String toGoatLatin(String S) {
StringBuilder sb = new StringBuilder();
String noOfA = "";
for(String s : S.split(" ")){
if(isVowel(s.charAt(0))) { //If vowel simply append it
sb.append(s);
}
else { //Else put at the end of string
char c = s.charAt(0);
sb.append(s.substring(1, s.length()));
sb.append(c);
}
noOfA += "a"; //Everytime it will increase by 1 a and so on..
sb.append("ma").append(noOfA).append(" ");
}
return sb.toString().trim();
}
private static boolean isVowel(char c){
return (c=='A' || c=='E' || c=='I' || c=='O' || c=='U' ||
c=='a' || c=='e' || c=='i' || c=='o' || c=='u');
}
}