Share my Java solution with explanation
\npublic int findComplement(int num) {\n        // find highest one bit\n\tint id = 31, mask = 1<<id;\n\twhile ((num & mask)==0) mask = 1<<--id;\n\t\t\n\t// mak
```\npublic int findComplement(int num) {\n        // find highest one bit\n\tint id = 31, mask = 1<<id;\n\twhile ((num & mask)==0) mask = 1<<--id;\n\t\t\n\t// make mask\n\tmask = (mask<<1) - 1;\n\t\t\n\treturn (~num) & mask;\n}\n```
[]