✅Java - One Line Code, Easy Explanation!!!
Idea\n\nBInary Complement of 5(101) is 2(010)\n\nSee,\nConvert all bits of 5(101) to ones i.e 111(5)\nNow we know the answer i.e 7(111)-5(101) =2(010) \n\nSo, f
**Idea**\n\nBInary Complement of 5(101) is 2(010)\n\nSee,\nConvert all bits of 5(101) to ones i.e 111(5)\nNow we know the answer i.e 7(111)-5(101) =2(010) \n\nSo, first find the size of bits of n i.e 3 in this case and pow(2,3)= 8 \nTherefore the answer be like 8-1-5=2\n\n````\nclass Solution {\n    public int bitwiseComplement(int n) {\n        \n        return (int)(Math.pow(2,Integer.toBinaryString(n).length())-1-n);\n\t\t//return (int)(Math.pow(2,Integer.toBinaryString(n).length())-1-n) also work\n\t\t//return ((2 << (int)(Math.log(Math.max(n, 1)) / Math.log(2))) - 1) - n; also work(0 ms)\n    }\n}\n````\n\nI hope you get it!!!\nPlease **upvote** if you liked the solution :))\n\nAll discussion are most welcomed!!!
['Java']