엔지니어 게시판
LeetCode 솔루션 분류

[11/4] 345. Reverse Vowels of a String

컨텐츠 정보

본문

Easy
28672273Add to ListShare

Given 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 * 105
  • s consist 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)
        
전체 396 / 4 페이지
번호
제목
이름

최근글


인기글


새댓글


Stats


알림 0