Re: [閒聊] 每日leetcode

作者: devilkool (對貓毛過敏的貓控)   2024-11-08 00:54:24
2275. Largest Combination With Bitwise AND Greater Than Zero
統計這些candidates的二進位數值哪個位元的1最多
就知道最多能AND多少數值最後大於零
public int LargestCombination(int[] candidates)
{
var count = new int[32];
for (int i=0;i<count.Length;i++)
{
foreach (var candidate in candidates)
{
if (((candidate >> i) & 1) > 0)
{
count[i]++;
}
}
}
return count.Max();
}

Links booklink

Contact Us: admin [ a t ] ucptt.com