My Python solution, which seems to cost too much time


  • 0
    L
    class Solution(object):
        def reverseVowels(self, s):
            VOWEL = ['a', 'e', 'i', 'o','u']
            str_list = list(s)
            vowel_index = []
            vowel_list = []
            for str_index in xrange (0, len(str_list)):
                if str_list[str_index].lower() in VOWEL:
                    vowel_index.append(str_index)
                    vowel_list.append(str_list[str_index])
            vowel_list.reverse()
            for each_index in vowel_index:
                str_list[each_index] = vowel_list[vowel_index.index(each_index)]
            return ''.join(map(str, str_list))
    

    Can anyone give me some suggestion?


Log in to reply
 

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