Re: [閒聊] 每日leetcode

作者: DJYOMIYAHINA (通通打死)   2025-09-11 23:49:29
就只會照做
第二個for loop應該可以改一下
不用每次都從頭找
大概是這樣
def sortVowels(self, s: str) -> str:
count = Counter(s)
rets = ""
for c in s:
if c in {'A','E','I','O','U','a','e','i','o','u'}:
for t_c in ['A','E','I','O','U','a','e','i','o','u']:
if count[t_c]>0:
rets += t_c
count[t_c] -= 1
break
else:
rets += c
return rets

Links booklink

Contact Us: admin [ a t ] ucptt.com