C++ 100% time winner O(1) space with comments inline
\nclass Solution {\npublic:\n    string maximumBinaryString(string binary) {\n        // We maintain 2 pointers and start from the highest bit.\n        // The 
```\nclass Solution {\npublic:\n    string maximumBinaryString(string binary) {\n        // We maintain 2 pointers and start from the highest bit.\n        // The 1st pointer go thru all bits, while the 2nd pointer find the next 0.\n        // If 1st pointer has \'1\' jump to the place of 2nd pointer,\n        // otherwise change the bit, e.g \'0110\' becomes \'1011\', and move 1st pointer to the next.\n        // Meanwhile find the next 0 and update 2nd pointer.\n        int len = binary.size(), i = 0, j = 1;\n        while (j < len && binary[j] != \'0\')\n        {\n            ++j;\n        }\n        \n        while (j < len)\n        {\n            if (binary[i] == \'1\')\n            {\n                i = j;  \n            }\n            else if (j < len)\n            {\n                binary[i] = \'1\';\n                binary[j] = \'1\';\n                binary[i + 1] = \'0\';\n                i += 1;\n            }\n            \n            j += 1;\n            while (j < len && binary[j] != \'0\')\n            {\n                ++j;\n            }\n        }\n        \n        return binary;\n    }\n};\n```
[]