Re: [閒聊] 每日leetcode
看板Marginalman作者DJYOSHITAKA (franchouchouISBEST)時間1年前 (2024/10/16 23:39)推噓0(0推 0噓 0→)留言0則, 0人參與討論串995/1548 (看更多)
好男喔
意外的不太會greedy
當個貪心的人好難
def longestDiverseString(self, a: int, b: int, c: int) -> str:
l = [[a, 'a'], [b, 'b'], [c, 'c']]
ans = ""
while True:
l.sort()
i = 2
if len(ans)>=2 and (ans[-1]==ans[-2]) and (ans[-2]==l[i][1]):
i = 1
if l[i][0] > 0:
ans += l[i][1]
l[i][0] -= 1
else:
break
return ans
--
※ 發信站: 批踢踢實業坊(ptt.cc), 來自: 125.229.37.69 (臺灣)
※ 文章網址: https://www.ptt.cc/bbs/Marginalman/M.1729093178.A.722.html
討論串 (同標題文章)
完整討論串 (本文為第 995 之 1548 篇):