Easy Solution || C++
Intuition\nThe code aims to find the complement of a given integer num. The complement is obtained by flipping each bit of the binary representation of the numb
# Intuition\nThe code aims to find the complement of a given integer `num`. The complement is obtained by flipping each bit of the binary representation of the number.\n\n# Approach\nThe code iterates through the binary representation of the input `num` one bit at a time. For each bit, it calculates the complement by performing XOR with 1. The complement is then added to the result after being multiplied by the appropriate power of 2. The loop continues until `num` becomes 0.\n\n# Complexity\n- Time complexity: $$O(log(n))$$, where n is the value of the input `num`. The loop runs for each bit in the binary representation of `num`.\n- Space complexity: $$O(1)$$, as only a constant amount of space is used for variables regardless of the input size.\n\n# Code\n```cpp\nclass Solution {\npublic:\n    int findComplement(int num) {\n        int bit;\n        int comp;\n        int dec_ans = 0;\n        int i = 0;\n        while(num != 0){\n            bit = num & 1;\n            comp = bit ^ 1;\n            dec_ans = comp * pow(2, i) + dec_ans;\n            num = num >> 1;\n            i++;\n        }\n\n        return dec_ans;\n    }\n};\n```
['Bit Manipulation', 'C++']