七月你好,国安法正式实施了,刷抖音那叫一个激动,咱们祖国就是厉害!
第70天——第70题(反转字符串中的元音字母)
看题目!
编写一个函数,以字符串作为输入,反转该字符串中的元音字母。
示例 1:
输入: "hello"
输出: "holle"
示例 2:
输入: "leetcode"
输出: "leotcede
python解答——指针
class Solution:
def reverseVowels(self, s: str) -> str:
length = len(s)
low, high = 0, length-1
s = list(s)
res =['a','e','i','o','u','A','E','I','O','U']
while low <= high:
while low< high and s[high] not in res:
high-=1
while low < high and s[low] not in res:
low += 1
s[low],s[high] = s[high],s[low]
low+=1
high-=1
return "".join(s)
作者:feng-hua-zheng-mao-7
链接:https://leetcode-cn.com/problems/reverse-vowels-of-a-string/solution/345-fan-zhuan-zi-fu-chuan-zhong-de-yuan-yin-zi-1-3/