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