Skip to content

Latest commit

 

History

History
30 lines (21 loc) · 519 Bytes

824.md

File metadata and controls

30 lines (21 loc) · 519 Bytes

Goat Latin

Description

link


Solution

  • See Code

Code

O(n)

class Solution:
    def toGoatLatin(self, S: str) -> str:
        vowel = set(['a','e','i','o','u','A','E','I','O','U'])
        res = []
        for i, w in enumerate(S.split()):
            if w[0] in vowel:
                res.append(w + 'ma' + (i+1) * 'a')
            else:
                res.append(w[1:] + w[0] + 'ma' + (i+1)*'a')
        return ' '.join(res)