Skip to content

LC 0824 [E] Goat Latin

Code with Senpai edited this page Jan 14, 2022 · 1 revision
class Solution:
    def toGoatLatin(self, sentence: str) -> str:
        words = sentence.split(' ')
        
        res = []
        
        for i, x in enumerate(words):
            s = ''
            
            if x[0].lower() in 'aeiou':
                s = x + 'ma'
            else:
                s = x[1:len(x)] + x[0] + 'ma'
                
            s += 'a' * (i+1)
                
            res.append(s)
        
        return ' '.join(res)
Clone this wiki locally