✅ [C++] EASY and Shorter Solution || Intuitive Approach || 100% Accepted
Intuition\n1. Straight formula based question.\n\n# Approach\n1. Count the number of digits in the number.\n2. Use the formula :- one complement of x is 2^n-x-1
# Intuition\n1. Straight formula based question.\n\n# Approach\n1. Count the number of digits in the number.\n2. Use the formula :- one complement of x is 2^n-x-1\n\n# Complexity\n- Time complexity:\nO(N)\n\n- Space complexity:\nO(1)\n\n# Code\n```\nclass Solution {\npublic:\n    int bitwiseComplement(int n) {\n\n        //one complement of x is 2^n-x-1\n\n        if(n==0)\n        return 1;\n\n        int count=0;\n        int d;\n        int m=n;\n        while(n!=0)\n        {\n           // d=n%10;\n            count++;\n            n=n>>1;\n        }\n        int res = pow(2,count)-m-1;\n        return res;\n    }\n};\n```
['C++']