Start Flipping From The First Set Bit From Left To Right Direction | Java | C++ | [Video Solution]
Intuition, approach, and complexity discussed in detail in video solution.\nhttps://youtu.be/qmC8KKKZGp0\n# Code\njava []\nclass Solution {\n    public int find
# Intuition, approach, and complexity discussed in detail in video solution.\nhttps://youtu.be/qmC8KKKZGp0\n# Code\n```java []\nclass Solution {\n    public int findComplement(int num) {\n       boolean setBitFound = false;\n       for(int bitPos = 30; bitPos > -1; bitPos--){\n            int mask = (1 << bitPos);\n            if((num & mask) != 0){\n                if(!setBitFound)setBitFound = true;\n            }\n            if(setBitFound){\n                num ^= mask;\n            }\n       }\n       return num;\n    }\n}\n```\n```cpp []\nclass Solution {\npublic:\n    int findComplement(int num) {\n       bool setBitFound = false;\n       for(int bitPos = 30; bitPos > -1; bitPos--){\n            int mask = (1 << bitPos);\n            if((num & mask) != 0){\n                if(!setBitFound)setBitFound = true;\n            }\n            if(setBitFound){\n                num ^= mask;\n            }\n       }\n       return num;\n    }\n};\n```
['Bit Manipulation', 'C++', 'Java']