Java | 0 ms | 1 liner | Explained
Idea:\n Flip all bits using negation operator (~) [read more here]\n Bitwise AND (&) with a bit mask of size n whose all bits are set, where n = number of bits 
**Idea:**\n* Flip all bits using negation operator (~) [[read more here](https://www.ibm.com/docs/en/i/7.1?topic=expressions-bitwise-negation-operator)]\n* Bitwise AND (&) with a bit mask of size n whose all bits are set, where n = number of bits in `num`\n**Example:**\n```\nnum = 5\n  num binary = 0...0101\n ~num binary = 1...1010\n\n* Now we\'ve flipped all the bits but it also flipped previously insignificant bits (0s), \nso to revert them back to 0s, we need to only keep the significant bits and turn off the insignificant bits\n* This can be done by using mask of 1s having size equal to number of bits in num. This mask is (1 << nBits) - 1\n* This is a standard mask in bit manipulation problems\n\n~num binary & mask = (1...1010) & (0...0111) = 0...0010 [Ans]\n```\n>**T/S:** O(1)/O(1)\n```\npublic int findComplement(int num) {\n\tvar nBits = (int) Math.floor((Math.log(num) / Math.log(2)) + 1);\n\tvar mask = (1 << nBits) - 1;\n\treturn ~num & mask;\n}\n```\n**Variation 2:** 1 liner variation of above method\n```\npublic int findComplement(int num) {\n\treturn ~num & (Integer.highestOneBit(num) - 1);\n}\n```\n***Please upvote if this helps***
['Java']