山羊拉丁文 难度:简单 最近力扣的题越来越那啥了 根据题意进行模拟即可。 代码如下:
public class GoatLatin {
static List<Character> list = new ArrayList();
static {
list.add('a');
list.add('e');
list.add('i');
list.add('o');
list.add('u');
}
public String toGoatLatin(String sentence) {
StringBuilder sb = new StringBuilder();
String[] splits = sentence.split(" ");
for (int i = 0; i < splits.length; i++) {
String substring = splits[i].substring(0, 1).toLowerCase();
if (list.contains(substring)){
sb.append(splits[i]);
}else{
sb.append(splits[i].substring(1)).append(splits[i].substring(0, 1));
}
sb.append("ma");
int time = i;
while(time-->=0){
sb.append("a");
}
sb.append(" ");
}
return sb.substring(0,sb.length()-1);
}
}
|