We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent f4d5bc9 commit da63bf5Copy full SHA for da63bf5
2429. Minimize XOR
@@ -0,0 +1,18 @@
1
+class Solution
2
+{
3
+public:
4
+ int minimizeXor(int x, int y)
5
+ {
6
+ int b = __builtin_popcount(y), A = 0;
7
+
8
+ for(int i = 31; i >= 0 && b; i--)
9
+ if(x & (1 << i))
10
+ b--, A |= (1 << i);
11
12
+ for(int i = 0; i <= 31 && b; i++)
13
+ if((A & (1 << i)) == 0)
14
15
16
+ return A;
17
+ }
18
+};
0 commit comments