Re: [闲聊] 每日leetcode

楼主: DJYOMIYAHINA (通通打死)   2024-11-07 21:45:45
每个bit去算 candidates里面有几个数字的这个bit是1
最多的那个就是答案
def largestCombination(self, candidates: List[int]) -> int:
cnt = defaultdict(int)
ans = 0
for sft in range(31):
cur_mask = (1<<sft)
for num in candidates:
if (num&cur_mask) > 0:
cnt[sft] += 1
ans = max(ans, cnt[sft])
return ans
楼主: DJYOMIYAHINA (通通打死)   2024-11-07 21:46:00
好像根本不用开map 对ㄚ==
作者: RinNoKareshi (立石凛的男友)   2024-11-07 21:47:00
大家都在看邦TV 就你还在卷= =
作者: dont   2024-11-07 21:49:00
大师
作者: Furina (芙宁娜)   2024-11-07 21:49:00
大师
作者: oin1104 (是oin的说)   2024-11-07 21:50:00
大师
作者: Che31128 (justjoke)   2024-11-07 21:52:00
大师

Links booklink

Contact Us: admin [ a t ] ucptt.com