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".
Note:
The vowels does not include the letter "y".
My code
class Solution(object):
def reverseVowels(self, s):
"""
:type s: str
:rtype: str
"""
vowelList=['A','a','O','o','E','e','I','i','U','u']
lowIndex = 0
highIndex = len(s)-1
s= list(s)
while lowIndex<=highIndex:
if s[lowIndex] in vowelList and s[highIndex] in vowelList:
s[lowIndex],s[highIndex]=s[highIndex],s[lowIndex]
lowIndex +=1
highIndex -=1
elif s[lowIndex] not in vowelList and s[highIndex] in vowelList:
lowIndex +=1
elif s[lowIndex] in vowelList and s[highIndex] not in vowelList:
highIndex -=1
else:
lowIndex +=1
highIndex -=1
return ('').join(s)
Notes:
s[lowIndex],s[highIndex]=s[highIndex],s[lowIndex]
('').join(s