此题和前面的344题反转字符串基本一样,不同之处是:1.反转的是字符串中的元音字母,2.输入的是字符串不是数组
class Solution:
def reverseVowels(self, s: str) -> str:
vow_letters = 'aeiouAEIOU'
left = 0
right = len(s) - 1
s = list(s)
while left < right:
if s[left] not in vow_letters:
left += 1
elif s[right] not in vow_letters:
right -= 1
else:
s[left], s[right] = s[right], s[left]
left += 1
right -= 1
return "".join(s)