[C++] O(1) using bitwise operator with explanation
\n/*\nnum          = 00000110\nmask         = 00000111\n~num         = 11111001\nmask & ~num  = 00000001\n*/\nint findComplement( int num ) {\n\tint mask = 0, t
```\n/*\nnum          = 00000110\nmask         = 00000111\n~num         = 11111001\nmask & ~num  = 00000001\n*/\nint findComplement( int num ) {\n\tint mask = 0, tmp=num;\n\twhile( tmp ) {\n\t\ttmp = tmp >> 1;\n\t\tmask = mask << 1;\n\t\tmask = mask | 1;\n\t}\n\treturn ~num & mask;\n}\n```
[]