Re: [閒聊] 每日leetcode
就只會照做
第二個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
--
※ 發信站: 批踢踢實業坊(ptt.cc), 來自: 220.132.58.28 (臺灣)
※ 文章網址: https://www.ptt.cc/bbs/Marginalman/M.1757605771.A.C99.html
討論串 (同標題文章)
完整討論串 (本文為第 1519 之 1548 篇):