# 345. Reverse Vowels of a String
Write a function that takes a string as input and reverse only the vowels of a string.
Example 1:
Input: "hello"
Output: "holle"
Example 2:
Input: "leetcode"
Output: "leotcede"
# Solution
Approach 1: two pointers.
# Code (Python)
Approach 1:
class Solution:
def reverseVowels(self, s: str) -> str:
# assuming returning a new string(not in place)
vowels = set(['a', 'e', 'i', 'o', 'u', 'A', 'E', 'I', 'O', 'U'])
result = list(s)
l, r = 0, len(result) - 1
while l < r:
while l < r and result[l] not in vowels:
l += 1
while l < r and result[r] not in vowels:
r -= 1
if l != r:
result[l], result[r] = result[r], result[l]
l += 1
r -= 1
return ''.join(result)
# Code (C++)
Approach 1:
Approach 2: