C++| Best approach beat 100%
Approach\n- When a \'0\' is found, the function checks whether this \'0\' is the first \'0\' or follows an earlier one (firstZeroIndex < i).\n- If the \'0\' is 
# Approach\n- When a \'0\' is found, the function checks whether this \'0\' is the first \'0\' or follows an earlier one (firstZeroIndex < i).\n- If the \'0\' is immediately after the firstZeroIndex, the two positions are swapped to push the \'0\' further to the right.\n- If not, the \'0\' is moved further to the right by shifting the first found \'0\' to \'1\', moving the current \'0\' to the next position (++firstZeroIndex), and setting the current position to \'1\'.\n- The loop backtracks (i--) to handle the case after a swap.\n\n# Complexity\n- Time complexity: O(n)\n\n- Space complexity: O(1)\n\n# Code\n```cpp []\nclass Solution {\npublic:\n    string maximumBinaryString(string binary) {\n    ios::sync_with_stdio(false);\n    cout.tie(nullptr);\n    cin.tie(nullptr);\n\n    int firstZeroIndex = 1000000;  // A large value to indicate no zero has been found yet\n    for (int i = 0; i < binary.size(); i++) {\n        if (binary[i] == \'0\') {\n            if (firstZeroIndex < i) {\n                if (i == firstZeroIndex + 1) {\n                    binary[firstZeroIndex] = \'1\';\n                    binary[i] = \'0\';\n                    firstZeroIndex = i;\n                } else {\n                    binary[firstZeroIndex] = \'1\';\n                    binary[++firstZeroIndex] = \'0\';\n                    binary[i] = \'1\';\n                    i--;  // Re-check the current position after shifting\n                }\n            } else {\n                firstZeroIndex = i;\n            }\n        }\n    }\n    return binary;\n}\n};\n```
['C++']