Easy Solution || C++
Intuition\nThe problem requires finding the bitwise complement of a given integer. Bitwise complement is the operation of flipping the bits of a binary represen
# Intuition\nThe problem requires finding the bitwise complement of a given integer. Bitwise complement is the operation of flipping the bits of a binary representation of a number (changing 0s to 1s and vice versa).\n\n# Approach\nThe provided code uses a bitwise operation to iterate through the bits of the input number `n`, flip each bit, and then construct the complemented number. The variable `dec_ans` is used to accumulate the result, and `multiplier` is used to keep track of the position of the current bit in the binary representation.\n\n1. Check if `n` is 0. If it is, return 1 as the bitwise complement of 0 is 1.\n\n2. Iterate through each bit of `n`:\n   - Extract the least significant bit using `n & 1`.\n   - Compute the complement of the bit using `bit ^ 1`.\n   - Update `dec_ans` by adding the complemented bit multiplied by the current position (`multiplier`).\n   - Right shift `n` to move to the next bit.\n   - Update the `multiplier` to move to the next position.\n\n3. Return the computed `dec_ans`.\n\n# Complexity\n- Time complexity: $$O(log(n))$$ where n is the input number. The while loop iterates through the bits of the number, and the number of bits in a number is log(n).\n- Space complexity: $$O(1)$$ as only a constant amount of additional space is used.\n\n# Code\n```\nclass Solution {\npublic:\n    int bitwiseComplement(int n) {\n        int bit;\n        int comp;\n        int multiplier = 1;\n        int dec_ans = 0;\n\n        if (n == 0) {\n            return 1;\n        } \n\n        while (n != 0) {\n            bit = n & 1;\n            comp = bit ^ 1;\n            dec_ans = comp * multiplier + dec_ans;\n            n = n >> 1;\n            multiplier *= 2;\n        }\n\n        return dec_ans;\n    }\n};\n```
['Bit Manipulation', 'C++']