編寫一個函式,以字串作為輸入,反轉該字串中的母音字母。
示例 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)