We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent 6a276d7 commit fbc3d13Copy full SHA for fbc3d13
0476. Number Complement.txt
@@ -0,0 +1,11 @@
1
+class Solution {
2
+ public int findComplement(int num) {
3
+ // example:
4
+ // num = 5(101)
5
+ // highestOneBit of 101 is 100
6
+ // highestOneMinusOne = 100 << 1, minus 1 = 0111
7
+ int highestOneMinusOne = (Integer.highestOneBit(num) << 1) - 1;
8
+ // ~ num = 1010
9
+ return ~ num & highestOneMinusOne;
10
+ }
11
+}
0 commit comments