Leetcode练习(Python):第345题:反转字符串中的元音字母:编写一个函数,以字符串作为输入,反转该字符串中的元音字母。
2021-01-05 22:29
                         标签:not   for   else   示例   eve   elf   list   大小写   dex    题目: 反转字符串中的元音字母:编写一个函数,以字符串作为输入,反转该字符串中的元音字母。 示例 1: 输入: "hello" 输入: "leetcode" 思路: 双指针,注意元音的大小写都要有。 程序:    Leetcode练习(Python):第345题:反转字符串中的元音字母:编写一个函数,以字符串作为输入,反转该字符串中的元音字母。 标签:not   for   else   示例   eve   elf   list   大小写   dex    原文地址:https://www.cnblogs.com/zhuozige/p/12979909.html
输出: "holle"
示例 2:
输出: "leotcede"
说明:
元音字母不包含字母"y"。class Solution:
    def reverseVowels(self, s: str) -> str:
        vowel_list = [‘a‘,‘e‘,‘i‘,‘o‘,‘u‘,‘A‘,‘E‘,‘I‘,‘O‘,‘U‘]
        if not s:
            return s
        if len(s) == 1:
            return s
        auxiliary = []
        for index in range(len(s)):
            auxiliary.append(s[index])
        index1 = 0
        index2 = len(auxiliary) - 1
        while index1 
文章标题:Leetcode练习(Python):第345题:反转字符串中的元音字母:编写一个函数,以字符串作为输入,反转该字符串中的元音字母。
文章链接:http://soscw.com/index.php/essay/40363.html