mirror of
https://github.com/devenperez/leetcode.git
synced 2026-06-13 03:27:07 +00:00
Time: 1259 ms (24.84%), Space: 22.2 MB (7.19%) - LeetHub
This commit is contained in:
@@ -0,0 +1,29 @@
|
||||
class Solution(object):
|
||||
def sortVowels(self, s):
|
||||
"""
|
||||
:type s: str
|
||||
:rtype: str
|
||||
"""
|
||||
ALL_VOWELS = set(['A', 'E', 'I', 'O', 'U', 'a', 'e', 'i', 'o', 'u'])
|
||||
|
||||
indices = []
|
||||
vowels = []
|
||||
|
||||
for i, letter in enumerate(s):
|
||||
if letter in ALL_VOWELS:
|
||||
indices += [i]
|
||||
vowels += [letter]
|
||||
|
||||
vowels.sort(key=ord)
|
||||
|
||||
newStr = ""
|
||||
j = 0
|
||||
|
||||
for i, letter in enumerate(s):
|
||||
if letter in ALL_VOWELS:
|
||||
newStr += vowels[j]
|
||||
j += 1
|
||||
else:
|
||||
newStr += s[i]
|
||||
|
||||
return newStr
|
||||
Reference in New Issue
Block a user