[leetcode]345. Reverse Vowels of a String
1028 ワード
345. Reverse Vowels of a String
Write a function that takes a string as input and reverse only the vowels of a string.
Example 1: Given s = “hello”, return “holle”.
Example 2: Given s = “leetcode”, return “leotcede”.
正規表現を使用して、listにアクセントアルファベットを配置し、pop()を置換します.シンプルで乱暴で優美なpythonコード
Write a function that takes a string as input and reverse only the vowels of a string.
Example 1: Given s = “hello”, return “holle”.
Example 2: Given s = “leetcode”, return “leotcede”.
正規表現を使用して、listにアクセントアルファベットを配置し、pop()を置換します.シンプルで乱暴で優美なpythonコード
class Solution(object):
def reverseVowels(self, s):
"""
:type s: str
:rtype: str
"""
vowels = re.findall('(?i)[aeiou]', s)
return re.sub('(?i)[aeiou]', lambda m:vowels.pop(), s)