Re: [闲聊] 每日leetcode

楼主: DJYOSHITAKA (Evans)   2024-10-16 23:39:36
好男喔
意外的不太会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

Links booklink

Contact Us: admin [ a t ] ucptt.com