[Java/C++/Python] Solution with Explanation
Explanation\nWe don\'t need touch the starting 1s, they are already good.\n\nFor the rest part,\nwe continually take operation 2,\nmaking the string like 00...0
# **Explanation**\nWe don\'t need touch the starting 1s, they are already good.\n\nFor the rest part,\nwe continually take operation 2,\nmaking the string like `00...00011...11`\n\nThen we continually take operation 1,\nmaking the string like `11...11011...11`.\n<br>\n\n# **Complexity**\nTime `O(n)`\nSpace `O(n)`\n<br>\n\n**Java:**\n```java\n    public String maximumBinaryString(String s) {\n        int ones = 0, zeros = 0, n = s.length();\n        StringBuilder res = new StringBuilder("1".repeat(n));\n        for (int i = 0; i < n; ++i) {\n            if (s.charAt(i) == \'0\')\n                zeros++;\n            else if (zeros == 0)\n                ones++;\n        }\n        if (ones < n)\n            res.setCharAt(ones + zeros - 1, \'0\');\n        return res.toString();\n    }\n```\n\n**C++:**\n```cpp\n    string maximumBinaryString(string s) {\n        int ones = 0, zeros = 0, n = s.length();\n        for (auto& c : s) {\n            if (c == \'0\')\n                zeros++;\n            else if (zeros == 0)\n                ones++;\n            c = \'1\';\n        }\n        if (ones < n)\n            s[ones + zeros - 1] = \'0\';\n        return s;\n    }\n```\n\n**Python:**\n```py\n    def maximumBinaryString(self, s):\n        if \'0\' not in s: return s\n        k, n = s.count(\'1\', s.find(\'0\')), len(s)\n        return \'1\' * (n - k - 1) + \'0\' + \'1\' * k\n```\n
[]