思路:
对撞指针
class Solution:
def reverseVowels(self, s: str) -> str:
s = list(s)
vowel_list = ['a', 'e', 'i', 'o', 'u', 'A', 'E', 'I', 'O', 'U']
left = 0
right = len(s) - 1
while left < right:
if s[left] not in vowel_list:
left += 1
if s[right] not in vowel_list:
right -= 1
if s[left] in vowel_list and s[right] in vowel_list:
s[left], s[right] = s[right], s[left] #交换
left += 1
right -= 1
return ''.join(s)