编写一个函数,以字符串作为输入,反转该字符串中的元音字母。
示例 1:
输入: "hello" 输出: "holle"
示例 2:
输入: "leetcode" 输出: "leotcede"
说明:
元音字母不包含字母"y"。
class Solution: def reverseVowels(self, s): """ :type s: str :rtype: str """ start = 0 end = len(s)-1 if end <= start: return s tmp = list(s) limit = 'aeiouAEIOU' while start < end: if tmp[start] not in limit: start += 1 elif tmp[end] not in limit: end -= 1 else: tmp[start],tmp[end]=tmp[end],tmp[start] start += 1 end -= 1 return ''.join(tmp)