Python solution-sharing


  • 0
    C
    class Solution(object):
        def reverseVowels(self, s):
            """
            :type s: str
            :rtype: str
            """
            lst = list(s)
            vowels_str = "aeiouAEIOU"
            vowels_list = [item for item in lst if item in vowels_str]
            vowels_list.reverse()
            vowels_index = 0
            for index, item in enumerate(lst):
                if item in vowels_str:
                    lst[index] = vowels_list[vowels_index]
                    vowels_index += 1
            return ''.join(lst)

Log in to reply
 

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