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