Re: [閒聊] 每日leetcode

看板Marginalman作者 (通通打死)時間1年前 (2024/11/07 21:45), 編輯推噓4(402)
留言6則, 6人參與, 1年前最新討論串1089/1548 (看更多)
每個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

11/07 21:46, 1年前 , 1F
好像根本不用開map 對ㄚ==
11/07 21:46, 1F

11/07 21:47, 1年前 , 2F
大家都在看邦TV 就你還在卷= =
11/07 21:47, 2F

11/07 21:49, 1年前 , 3F
大師
11/07 21:49, 3F

11/07 21:49, 1年前 , 4F
大師
11/07 21:49, 4F

11/07 21:50, 1年前 , 5F
大師
11/07 21:50, 5F

11/07 21:52, 1年前 , 6F
大師
11/07 21:52, 6F
文章代碼(AID): #1dBCIBpq (Marginalman)
討論串 (同標題文章)
文章代碼(AID): #1dBCIBpq (Marginalman)