题目描述:
824. 山羊拉丁文 - 力扣(LeetCode) (leetcode-cn.com)
自测用例:
"I speak Goat Latin"
"The quick brown fox jumped over the lazy dog"
"I"
"i"
"am"
"he"
Java代码:
class Solution {
public String toGoatLatin(String s) {
String[] a=s.split(" ");
boolean[] b=new boolean['z'+1];
for(int e:new int[]{'a','e','i','o','u'})b[e]=b[e-32]=true;
StringBuilder sb=new StringBuilder();
for(int i=0;i<a.length;i++){
if(i!=0)sb.append(' ');
if(b[a[i].charAt(0)])sb.append(a[i]).append("ma");
else sb.append(a[i].substring(1)).append(a[i].charAt(0)).append("ma");
for(int j=0;j<=i;j++)sb.append('a');
}
return sb.toString();
}
}
?
|