2025-08-01 04:59:37 +0000 UTC
Goat Latin
Categories:
Links
Code
class Solution:
def toGoatLatin(self, sentence: str) -> str:
cur_word = []
res = []
i = 0
for char in itertools.chain(sentence, " "):
if char != " ":
cur_word.append(char)
continue
if not cur_word:
continue
i += 1
if cur_word[0].lower() in ("a", "e", "i", "o", "u"):
cur_word.append("ma")
else:
cur_word.append(cur_word[0])
cur_word.append("ma")
cur_word[0] = ""
cur_word.append("a" * i)
res.append("".join(cur_word))
cur_word.clear()
return " ".join(res)