2 liner using list comprehension

  • 0
        def reverseVowels(self, s):
            vowels = [x for x in s if x in 'aeiouAEIOU']
            return ''.join([x if x not in 'aeiouAEIOU' else vowels.pop() for x in s])
    # could check for x.lower() in 'aeiou' but it looks like check for 'aeiouAEIOU' is faster - comments?

Log in to reply

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.