Accepted - Python code


  • 1
    S
    class Solution(object):
        def reverseVowels(self, s):
            l = list(s)
            rev=[]
            idx = []
            index=0
            res=""
            
            for i in l:
                if i in ['a','e','i','o','u','A','E','I','O','U']:
                    rev.append(i)
                    idx.append(index)
                index += 1
                    
            
            val = 0
            while(len(rev)>0):
                l[idx[val]]=rev.pop()
                val += 1
            
            return res.join(l)

Log in to reply
 

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