Skip to content

Latest commit

 

History

History
50 lines (34 loc) · 1.08 KB

_345. Reverse Vowels of a String.md

File metadata and controls

50 lines (34 loc) · 1.08 KB

All prompts are owned by LeetCode. To view the prompt, click the title link above.

Back to top


First completed : May 23, 2024

Last updated : July 01, 2024


Related Topics : Two Pointers, String

Acceptance Rate : 53.662 %


Solutions

Python

class Solution:
    def reverseVowels(self, s: str) -> str:
        s = list(s)
        left, right = 0, len(s) - 1

        vowels = set('aeiouAEIOU')
        while left < right :
            if s[left] not in vowels :
                left += 1
                continue
            if s[right] not in vowels :
                right -= 1
                continue
            
            s[left], s[right] = s[right], s[left]

            left += 1
            right -= 1
            
        return ''.join(s)