Java Simple Brute Force Approach
Intuition\n Describe your first thoughts on how to solve this problem. \nThe problem asks us to find the complement of a given integer. The complement of a bina
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\nThe problem asks us to find the complement of a given integer. The complement of a binary number is obtained by flipping all the bits (i.e., converting 0s to 1s and 1s to 0s). The basic idea is to convert the number into its binary form, flip the bits, and then convert it back to a decimal number.\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\nConvert the given integer num to its binary representation.\nIterate through each bit of the binary number:\nIf the bit is 1, change it to 0.\nIf the bit is 0, change it to 1.\nConvert the modified binary string back to a decimal number, which will be the complement of the original number.\n\n# Complexity\n- Time complexity: O(logn)\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity: O(logn)\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\n\n# Code\n```java []\nclass Solution {\n    public int findComplement(int num) {\n        StringBuilder s = new StringBuilder();\n        while (num > 0) {\n            int t = num % 2;\n            s.insert(0, t);\n            num /= 2;\n        }\n        for (int i = 0; i < s.length(); i++) {\n            if (s.charAt(i) == \'1\') {\n                s.setCharAt(i, \'0\');\n            }\n            else {\n                s.setCharAt(i, \'1\');\n            }\n        }\n        return Integer.parseInt(s.toString(), 2);\n    }\n}\n\n```
['Java']