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)