Simple PYTHON


  • 0
    V
    class Solution(object):
        def reverseVowels(self, s):
            """
            :type s: str
            :rtype: str
            """
            strlst = list(s)
            l = 0
            r = len(s) - 1
            vowels = {'a','e','i','o','u','A','E','I','O','U'}
            
            while l <= r:
                if strlst[l] not in vowels:
                    l += 1
        
                if strlst[r] not in vowels:
                    r -= 1
                
                if l <= r and strlst[l] in vowels and strlst[r] in vowels:
                    tmp = strlst[l]
                    strlst[l] = strlst[r]
                    strlst[r] = tmp
                    l += 1
                    r -= 1
            
            return ''.join(strlst)
                
                
                
    

Log in to reply
 

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