LeetCode 솔루션 분류
[11/4] 345. Reverse Vowels of a String
본문
Easy
28672273Add to ListShareGiven a string s, reverse only all the vowels in the string and return it.
The vowels are 'a', 'e', 'i', 'o', and 'u', and they can appear in both lower and upper cases, more than once.
Example 1:
Input: s = "hello" Output: "holle"
Example 2:
Input: s = "leetcode" Output: "leotcede"
Constraints:
1 <= s.length <= 3 * 105sconsist of printable ASCII characters.
Accepted
450,309
Submissions
909,440
관련자료
-
링크
댓글 1
학부유학생님의 댓글
- 익명
- 작성일
class Solution:
def reverseVowels(self, s: str) -> str:
stack = []
s=list(s)
for char in s:
if char in "aeiouAEIOU": stack.append(char)
res = [stack.pop() if char in "aeiouAEIOU" else char for char in s ]
return "".join(res)







