Re: [闲聊] 每日leetcode

楼主: dont   2025-01-15 19:53:25
2429. Minimize XOR
## 思路
先计算num2的bits数
位数从高往低 把num1的1消掉
如果bit还有剩就从低到高遇到0塞1
## Code
```cpp
class Solution {
public:
int minimizeXor(int num1, int num2) {
int bitCount = __builtin_popcount(num2);
int res = 0;
for (int i=31; i>=0 && bitCount >= 1;

Links booklink

Contact Us: admin [ a t ] ucptt.com