Re: [閒聊] 每日leetcode

作者: DJYOSHITAKA (Evans)   2024-06-06 20:04:50
感覺應該還可以剪一些枝
懶剪了
def isNStraightHand(self, hand: List[int], groupSize: int) -> bool:
cnt = defaultdict(int)
for i in hand:
cnt[i] += 1
sorted_keys = sorted(cnt.keys())
for k in sorted_keys:
cnt_cur = cnt[k]
if cnt_cur>0:
for i in range(groupSize):
if (k+i) in cnt.keys():
cnt[k+i] = cnt[k+i]-cnt_cur
else:
return False
elif cnt_cur<0:
return False
return True
作者: msd28437 (xiaojie)   2024-06-06 20:06:00
沒大引號 失敗
作者: sustainer123 (caster)   2024-06-06 20:22:00
python又沒大引號

Links booklink

Contact Us: admin [ a t ] ucptt.com