Easy JAVA solution || 3-Line Code || T.C. : O(1) || S.C. : O(1)
Intuition\n We are tasked with finding the complement of the given integer \'num\' in binary representation.*\n# Approach\n 1. Convert the given integer \'num\'
# Intuition\n We are tasked with finding the complement of the given integer \'num\' in binary representation.*\n# Approach\n 1. Convert the given integer \'num\' to its binary representation using Integer.toBinaryString(num).\n 2. Calculate the number of bits required to represent \'num\' using the length of its binary representation \'n\'.\n 3. Create a bitmask \'h\' by using the left shift (<<) operator to set all \'n\' bits to 1.\n 4. Calculate the complement by applying the bitwise XOR (^) operation between \'h\' and \'num\'.\n 5. Return the computed complement as the result.\n\n# Complexity\n- Time complexity:\n  O(1) because it has a constant number of operations that do not depend on the input size. \n\n- Space complexity: \n The space used for variables and computations is constant, so the space complexity is O(1).\n\n# Code\n```\nclass Solution {\n    public int findComplement(int num) {\n        int n=Integer.toBinaryString(num).length();\n        int h= (1 << n) - 1;\n        return h ^ num;\n    }\n}\n\n\n```
['Java']