Reverse vowels of a string
class Solution:
def reverseVowels(self, s: str) -> str:
lst = list(s)
left = 0
right = len(s) - 1
vowels = ['a', 'A', 'e', 'E', 'i', 'I', 'o', 'O', 'u', 'U']
while left < right:
if lst[left] in vowels and lst[right] in vowels:
lst[left], lst[right] = lst[right], lst[left]
left += 1
right -= 1
elif lst[left] in vowels:
right -= 1
else:
left += 1
return "".join(lst)
Reverse Vowels of a String
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 * 105sconsist of printable ASCII characters.