编写一个函数,以字符串作为输入,反转该字符串中的元音字母。
示例 1:
输入: “hello”
输出: “holle”
示例 2:
输入: “leetcode”
输出: “leotcede”
说明:
元音字母不包含字母"y"。
class Solution(object):
def reverseVowels(self, s):
"""
:type s: str
:rtype: str
aeiouAEIOU
"""
result = list(s)
yin = []
for i in s:
if i in 'aeiouAEIOU':
yin.append(i)
for i in range(len(result)):
if result[i] in 'aeiouAEIOU':
result[i] = yin.pop()
result = "".join(result)
return result
本文介绍了一个Python函数,该函数接收一个字符串作为输入,并反转其中的元音字母。通过实例演示了如何实现这一功能,包括对hello和leetcode等字符串的处理。
2216

被折叠的 条评论
为什么被折叠?



