JAVA - 2 line with Explanation - Bit Manipulation - 0ms
Num + Complement = All 1\'s\nSo, Complement = All 1\'s - Num\n\nExample :\nnum = 5 = 101\ncomplement = 2 = 010\n\n101 + 010 = 111\n101 + complement = 111\nSo, c
Num + Complement = All 1\'s\nSo, Complement = All 1\'s - Num\n\n**Example :**\nnum = 5 = 101\ncomplement = 2 = 010\n\n101 + 010 = 111\n**101 + complement = 111\nSo, complement = 111 - 101\n               = 010**\n\n# Code\n```\nclass Solution {\n    public int findComplement(int num) {\n    int n = 0;\n        while (n < num) {\n            n = (n << 1) | 1;\n        }\n        return n - num;\n    }\n}\n```
['Bit Manipulation', 'Java']