参考代码:
class Solution:
def reverseVowels(self, s):
vowels = set(["a", "e", "i", "o", "u", "A", "E", "I", "O", "U"])
res = list(s)
start, end = 0, len(res) = -1
while start <= end:
while start <= end and res[start] not in vowels:
start += 1
while start <= end and res[end] not in vowels:
end -= 1
if start <= end:
res[start], res[end] = res[end], res[start]
start += 1
end -= 1
return "".join(res)