首页 > 其他 > 详细

345.Reverse Vowel of a String

时间:2018-11-05 16:06:10      阅读:165      评论:0      收藏:0      [点我收藏+]

Write a function that takes a string as input and reverse only the vowels of a string.

Example 1:

Input: "hello"
Output: "holle"

Example 2:

Input: "leetcode"
Output: "leotcede"

Note:
The vowels does not include the letter "y".

class Solution:
    def reverseVowels(self, s):
        """
        :type s: str
        :rtype: str
        """
        temp = []
        s = list(s)
        for i in s:
            if i in [‘a‘,‘e‘,‘i‘,‘o‘,‘u‘,‘A‘,‘E‘,‘I‘,‘O‘,‘U‘]:
                temp.append(i)
        temp.reverse()
        pos = 0
        for i in range(len(s)):
            if s[i] in [‘a‘,‘e‘,‘i‘,‘o‘,‘u‘,‘A‘,‘E‘,‘I‘,‘O‘,‘U‘]:
                s[i] = temp[pos]
                pos += 1
        return ‘‘.join(s)

345.Reverse Vowel of a String

原文:https://www.cnblogs.com/bernieloveslife/p/9771761.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!