Make The String Great
Written by Ron on 010111 April 000112011. Posted in Blog
Given a string s, reverse only all the vowels in the string and return it.
The vowels are 'a', 'e', 'i', 'o', and 'u', and they can appear in both lower and upper cases, more than once.
Example 1:
Input: s = "hello"
Output: "holle"
class Solution:
def reverseVowels(self, s: str) -> str:
vowels = []
_str = list(s)
for i in range(len(s)):
if s[i] in "aeiouAEIOU":
vowels.append(s[i])
for i in range(len(s)):
if s[i] in "aeiouAEIOU":
_str[i] = vowels.pop()
return ''.join(_str)
s = Solution()
print(s.reverseVowels("aA"))#"Aa"
print(s.reverseVowels("hello"))#"holle"