824. 山羊拉丁文
为保证权益,题目请参考 824. 山羊拉丁文(From LeetCode).
解决方案1
Python
python
# 824. 山羊拉丁文
# https://leetcode-cn.com/problems/goat-latin/
from functools import reduce
class Solution:
def toGoatLatin(self, sentence: str) -> str:
words = sentence.split(" ")
new_words = []
for i, word in enumerate(words, 1):
if word[0] in "AEIOUaeiou":
new_word = word + "ma"
else:
new_word = word[1:]+word[0]+"ma"
new_word = new_word + "a" * i
new_words.append(new_word)
new_sentence = " ".join(new_words)
return new_sentence
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20