[c++] O(n) Solution
\n\nclass Solution {\npublic:\n    string maximumBinaryString(string bin) {\n        int i = 0, n = bin.size(), last = -1;\n        for (int i = 0; i < n; ++i){
\n```\nclass Solution {\npublic:\n    string maximumBinaryString(string bin) {\n        int i = 0, n = bin.size(), last = -1;\n        for (int i = 0; i < n; ++i){\n            if (bin[i] == \'0\'){\n                if (last != -1){\n                    bin[last] = \'1\', bin[last+1] = \'0\';\n                    if (i != last+1)\n                        bin[i] = \'1\';\n                    last++;\n                }\n                else{\n                    last = i;\n                }\n            }\n                \n        }\n        return bin;\n        \n    }\n};\n```
['C', 'C++']