1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
| # 太离谱了,除了变量命名不一样,他的运行比我快
# 复制成他的,速度快了,莫非是代码格式化的问题
# 36ms
def toGoatLatin(self, sentence: str) -> str:
l = ['a','e','i','o','u','A','E','I','O','U']
words = sentence.split(' ')
for i, word in enumerate(words):
if word[0] in l:
words[i] = word + 'ma' + 'a'*(i+1)
else:
words[i] = word[1:] + word[0] + 'ma' + 'a' * (i+1)
return ' '.join(words)
# 20ms
def toGoatLatin(self, sentence: str) -> str:
l=['a','e','i','o','u','A','E','I','O','U']
words=sentence.split(' ')
for i,word in enumerate(words):
if word[0] in l:
words[i]=word+'ma'+'a'*(i+1)
else:
words[i]=word[1:]+word[0]+'ma'+'a'*(i+1)
return ' '.join(words)
|