2 java simple solutions with comments | 100% runtime
\n1st solution:-\n\nclass Solution {\n    public int findComplement(int num) {\n        int i = 0, res = 0;\n        while(num > 0){\n            // if last bit
```\n1st solution:-\n\nclass Solution {\n    public int findComplement(int num) {\n        int i = 0, res = 0;\n        while(num > 0){\n            // if last bit of num is 0, then we need to take complement of it\n            // so, add corresponding pow to res.\n            if((1 & num) == 0) res += Math.pow(2, i);\n            i++;\n            num = num >> 1;\n        }\n        return res;\n    }\n}\n\n2nd solution:-\n// same logic as above solution. but different implementation\nclass Solution {\n    public int findComplement(int num) {\n        int power = 1, res = 0;\n        while(num > 0){\n            res += ((1 & num) ^ 1) * power;\n            power <<= 1;\n            num >>= 1;\n        }\n        return res;\n    }\n}\n```\n**If you have any doubts, feel free to ask.\n   if you understand, don\'t forget to upvote \u25C9\u203F\u25C9**
[]