Python solution using stack


  • 0
    J
    class Solution(object):
        def reverseVowels(self, s):
            """
            :type s: str
            :rtype: str
            """
            vowels = 'aeiouAEIOU'
            stack = []
            for char in s:
                if char in vowels:
                    stack.append(char)
            return ''.join(char if char not in vowels else stack.pop() for char in s)
    

Log in to reply
 

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