Python solution


  • 3
    H
    class Solution(object):
        def reverseVowels(self, s):
            """
            :type s: str
            :rtype: str
            """
            vowels='aeiouAEIOU'
            vpos=[i for i,j in enumerate(s) if j in vowels]
            svrev=list(s)
            i,j=0,len(vpos)-1
            while i<j:
                svrev[vpos[i]],svrev[vpos[j]]=svrev[vpos[j]],svrev[vpos[i]]
                i+=1
                j-=1
            return ''.join(svrev)

  • 1
    A

    Such an unreadable format :(


  • 0
    Z

    class Solution(object):

    def reverseVowels(self, s):
    
        s = list(s)
        vowel =[]
        for i in s:
            if i.lower() in ('a','e', 'i', 'o' ,'u'):
                vowel.append(str(i))
        #print vowel
        vl = len(vowel)
    
        for i in range(len(s)):
            if s[i].lower() in ('a','e', 'i', 'o' ,'u'):
                s[i] =  vowel[vl-1]
                vl = vl - 1
            
    
        return ''.join(s)

Log in to reply
 

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