题目
![](https://img.laitimes.com/img/_0nNw4CM6IyYiwiM6ICdiwiI0gTMx81dsQWZ4lmZf1GLlpXazVmcvwFciV2dsQXYtJ3bm9CX9s2RkBnVHFmb1clWvB3MaVnRtp1XlBXe0xCMy81dvRWYoNHLwEzX5xCMx8FesU2cfdGLwMzX0xiRGZkRGZ0Xy9GbvNGLpZTY1EmMZVDUSFTU4VFRR9Fd4VGdsYTMfVmepNHLrJXYtJXZ0F2dvwVZnFWbp1zczV2YvJHctM3cv1Ce-cmbw5yM1gTNzEDNlBjN4QmN4U2YyYzX0IDO0YTMzEzLcdDMyIDMy8CXn9Gbi9CXzV2Zh1WavwVbvNmLvR3YxUjLyM3Lc9CX6MHc0RHaiojIsJye.png)
思路
代码
class Solution(object):
def reverseVowels(self, s):
"""
:type s: str
:rtype: str
"""
# print(type(s)) # <type 'unicode'>
cs = 'aeiouAEIOU' # 要考虑大小写,元音字母的大写也写进去
i,j = 0,len(s)-1
s = list(s) # <type 'unicode'>转换为list
while i<j:
while i<j and s[i] not in cs:
i += 1
while i<j and s[j] not in cs:
j -= 1
s[i],s[j] = s[j],s[i]
i += 1
j -= 1
return "".join(s) #list转换为字符串