C++ Solution EXPLAINED FULLY
Approach  : \n1. First we will find the number of bits in the given integer \n2. Then we will find the maximum number having same number of bits.(call it x )\n3
Approach  : \n1. First we will find the number of bits in the given integer \n2. Then we will find the maximum number having same number of bits.(call it x )\n3. Then we will XOR the given integer with x\n\nFor example : If input is 5 ,Binary Rep = 101 the number of bits = 3\n\t\t\t\t\tMax number , x = pow(2,number of bits) - 1 = pow(2,3) - 1  = 7\n\t\t\t\t\tBinary Rep of x = 111\n\t\t\t\t\tOur ans = XOR of ( given num and x ) = 101 XOR 111 = 010 = 2 (in decimal )\n\n\n\n\n```\n\n```public:\n    int findComplement(int num) {\n        if(num == 0)\n            return 1 ;\n        int p = log2(num)+  1 ;\n        int x = pow(2, p) - 1 ; \n        return num ^ x ;\n        }\n};\n```\nNote : log2(num) returns 1 less than total number of bits , so we add 1 .\n\nFeel free to comment  :)
[]