力扣345. 反转字符串中的元音字母

原题

 1 class Solution:
 2     def reverseVowels(self, s: str) -> str:
 3         left,right,word,ans = 0,len(s)-1,'aeiouAEIOU',list(s)
 4         while left < right:
 5             flag1,flag2 = ans[left] in word, ans[right] in word
 6             if flag1 and flag2:
 7                 ans[left],ans[right] = ans[right],ans[left]
 8                 left += 1
 9                 right -= 1
10             left += (1 - int(flag1))
11             right -= (1 - int(flag2))
12         return ''.join(ans)

 

上一篇:CF1445A Array Rearrangement 题解


下一篇:mysql 批量加减时间