Java | 100% Faster | With Comments
```\nclass Solution {\n    public int findComplement(int num) {\n        int result = 0;\n        //use set to set the value of result in each bit\n        int 
```\nclass Solution {\n    public int findComplement(int num) {\n        int result = 0;\n        //use set to set the value of result in each bit\n        int set = 1;\n        while(num != 0) {\n            //if last bit is 0 , set corresponding position of result to 1\n            if((num&1)== 0) {\n                result |= set;\n            }\n            //if last bit of num is 1, then do not need to set result\n            set <<= 1; // left shift 1 bit\n            num >>= 1;//right shift num, move right 1 bit\n        }\n        return result;\n    }\n}
['Java']