100.00% | 3 line easy short | c++ code | math | O(log2(n))
Approach\n Describe your approach to solving the problem. \nJust find the just greater number than n which is power of 2 then subtact 1 from it.\nThen return xo
# Approach\n<!-- Describe your approach to solving the problem. -->\nJust find the just greater number than n which is power of 2 then subtact 1 from it.\nThen return xor of both\n\n# Code\n```cpp []\nclass Solution {\npublic:\n    int bitwiseComplement(int n) {\n        unsigned int b=0,k=0;\n        while(k<=n)b++,k=pow(2,b);\n        return (k-1)^n;\n    }\n};\n```\n# Complexity\n- Time complexity: O(log2(n))\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity: O(1)\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\n
['C++']