Simple Python Beat 95%


  • 0
    class Solution(object):
        def reverseVowels(self, s):
            viwel = {'a', 'e', 'i', 'o', 'u', 'A', 'E', 'I', 'O', 'U'}
            s = list(s)
            left, right = 0, len(s) - 1
            while left < right:
                while left < right and s[left] not in viwel:
                    left += 1
                while left < right and s[right] not in viwel:
                    right -= 1
                if left < right:
                    s[left], s[right] = s[right], s[left]
                    left, right = left + 1, right - 1
            return ''.join(s)
    

Log in to reply
 

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