본문 바로가기
python-algorithm

leetcode 345. Reverse Vowels of a String

by 무적김두칠 2022. 4. 21.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
class Solution:
    def reverseVowels(self, s: str-> str:
        vowels=['a','e','i','o','u','A','E','I','O','U']
        my_vowel=[]
        start=0
        ans=''
        for i in s:
            if i in vowels : my_vowel.append(i)
        my_vowel=my_vowel[::-1]
        for i in s:
            if i in vowels :
                ans+=my_vowel[start]
                start+=1
            else: ans+=i
        return(ans)
cs
반응형

댓글