-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathGoat_Latin_824.java
41 lines (36 loc) · 1 KB
/
Goat_Latin_824.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
package leetcode;
class Solution824 {
public String toGoatLatin(String sentence) {
String[] senSplited = sentence.split("\s");
String ans = "";
for (int i = 0; i < senSplited.length; i++) {
ans += getLatin(senSplited[i], i) + " ";
}
return ans.trim();
}
public String getLatin(String word, int pos) {
StringBuilder sb = new StringBuilder(word);
char ex = word.charAt(0);
// System.out.println(sb);
if (ex == 'a' || ex == 'e' || ex == 'i' || ex == 'o' || ex == 'u' || ex == 'A' || ex == 'E' || ex == 'I'
|| ex == 'O' || ex == 'U') {
sb.append("ma");
} else {
sb.replace(0, 1, "");
sb.append(ex + "ma");
// sb.append();
}
for (int i = 0; i <= pos; i++) {
sb.append("a");
}
return sb.toString();
}
}
public class Goat_Latin_824 {
public static void main(String[] args) {
Solution824 ns = new Solution824();
String sen = "Each word consists of lowercase and uppercase letters only";
System.out.println(ns.toGoatLatin(sen));
System.out.println("ans = " + "");
}
}