Very-easy-to-understand Python solution

  • 0

    moving two pointers in the opposite direction, swap letters pointed by the two pointers when both of them point to vowels, until they meet.

    class Solution(object):
        def reverseVowels(self, s):
            vowls = ['a', 'e', 'i', 'o', 'u']
            s = [c for c in s]
            i, j = 0, len(s)-1
            while i<j:
                while i<j and (s[i].lower() not in vowls):
                while i<j and (s[j].lower() not in vowls):
                if i<j:
                    s[i], s[j] = s[j], s[i]
            return ''.join(s)

Log in to reply

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