Re: [閒聊] 每日leetcode
每個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
11/07 21:46, 1F
→
11/07 21:47,
1年前
, 2F
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
討論串 (同標題文章)
完整討論串 (本文為第 1089 之 1548 篇):