Java Bit masking 100% faster
\nclass Solution {\n    public int findComplement(int num) {\n        int c = 0, t = num;\n\t\t//First, you need to find how many bits are present in the given 
```\nclass Solution {\n    public int findComplement(int num) {\n        int c = 0, t = num;\n\t\t//First, you need to find how many bits are present in the given number.\n        while(t>0) {\n            t = t>>1;\n            c++;\n        }\n\t\t//Now after that, create a mask of 1\'s about the size of num.\n\t\t//eg: if num = 5(101) then mask = 7(111) \n        int mask = (1<<(c))-1;\n\t\t//now this mask can be used to flip all the bits in num using XOR.\n        return num^mask;\n    }\n}\n```
['Java']