345. Reverse Vowels of a String 【E】

来源:互联网 发布:犀牛o2o源码 编辑:程序博客网 时间:2024/05/18 00:36

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".


Subscribe to see which companies asked this question

这个也是很简单,不过要注意元音字母还包括大写字母。。。


class Solution(object):    def reverseVowels(self, s):        v = ['a','e','i','o','u','A','E','I','O','U']        vovs = []        s = list(s)        for i in xrange(len(s)):            if s[i] in v:                vovs += s[i],                s[i] = None        #vovs.reverse()        #print vovs,s        for i in xrange(len(s)):            if s[i] == None:                s[i] = vovs.pop()        #print s        return ''.join(s)


0 0