将一个字符串中的元音按ASCII码排序,其他字母位置不变
1 #2785
2 #Runtime: 175 ms (Beats 90.41%)
3 #Memory: 30 MB (Beats 6.85%)
4
5 class Solution(object):
6 def sortVowels(self, s):
7 """
8 :type s: str
9 :rtype: str
10 """
11 s, vols, pos = list(s), [], []
12 vol_set = set(['a', 'e', 'i', 'o', 'u', 'A', 'E', 'I', 'O', 'U'])
13 for i, ch in enumerate(s):
14 if ch in vol_set:
15 vols.append(ch)
16 pos.append(i)
17 vols.sort()
18 for i, ch in zip(pos, vols):
19 s[i] = ch
20 return ''.join(s)