Write a function that takes a string as input and reverse only the vowels of a string.
Input: "hello" Output: "holle"
Input: "leetcode" Output: "leotcede"
The vowels does not include the letter "y".
class Solution:
def reverseVowels(self, s: str) -> str:
s = list(s)
vowels = "aiueoAIUEO"
i = 0
j = len(s) - 1
while i < j:
while i < j and s[i] not in vowels:
i += 1
while i < j and s[j] not in vowels:
j -= 1
s[i], s[j] = s[j], s[i]
i += 1
j -= 1
return ''.join(s)
# @param {String} s
# @return {String}
def reverse_vowels(s)
vowels = "aiueoAIUEO"
i, j = 0, s.length - 1
while i < j
while i < j and not vowels.include?(s[i])
i += 1
end
while i < j and not vowels.include?(s[j])
j -= 1
end
s[i], s[j] = s[j], s[i]
i += 1
j -= 1
end
return s
end