精華區beta Marginalman 關於我們 聯絡資訊
每個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 -- ※ 發信站: 批踢踢實業坊(ptt.cc), 來自: 125.229.37.69 (臺灣) ※ 文章網址: https://www.ptt.cc/bbs/Marginalman/M.1730987147.A.CF4.html
DJYOMIYAHINA: 好像根本不用開map 對ㄚ== 11/07 21:46
RinNoKareshi: 大家都在看邦TV 就你還在卷= = 11/07 21:47
dont: 大師 11/07 21:49
Furina: 大師 11/07 21:49
oin1104: 大師 11/07 21:50
Che31128: 大師 11/07 21:52