🚀Beats 100%🔥🤩||Super Clean✅||Easy code with explanation..
Intuition & Approach\n Describe your approach to solving the problem. \n1. The code constructs a bitmask that has all bits set up to the most significant bit of
# Intuition & Approach\n<!-- Describe your approach to solving the problem. -->\n1. The code constructs a bitmask that has all bits set up to the most significant bit of n by shifting and OR operations.\n2. It then uses bitwise NOT (~) on n to flip all bits.\n3. Finally, it performs a bitwise AND with the bitmask to get the complement.\n\n# Complexity\n- **Time complexity: O(logN)**\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# ***PS - Please upvote (bottom left) if this solution was helpful :) It motivates me to write more solutions***\n![upvoteee_meeee.png](https://assets.leetcode.com/users/images/0d409230-9612-481f-b98b-5590cb38fbe9_1704209477.4691582.png)\n\n\n# Code\n```\nclass Solution {\npublic:\n    int bitwiseComplement(int n) {\n       int mask = 0;\n       int temp = n;\n       if(temp==0)\n            return 1;//edge case\n       while(temp>0){\n           mask = (mask<<1)|1;\n           temp = temp>>1;\n       }\n        int ans = (~n) & mask;\n        return ans;\n    }\n};\n```
['Bit Manipulation', 'Bitmask', 'C++']