二进制下的贪心。(用bitset更方便)
class Solution {
public:
int minimizeXor(int num1, int num2) {
bitset<32> b1(num1), b2(num2), b3;
int cnt_2 = b2.count();
for(int i = 31; i >= 0 && cnt_2 > 0; i--){
if(b1[i] == 1){
b3[i] = 1;
cnt_2--;
}
}
for(int i = 0; i < 32 && cnt_2 > 0; i++){
if(b3[i] == 0){
b3[i] = 1;
cnt_2--;
}
}
return int(b3.to_ulong());
}
};