Magic solution
I don\'t remember how I figured out this pattern\n\n# Code\n\nclass Solution:\n    def maximumBinaryString(self, binary: str) -> str:\n        idx = binary.find
I don\'t remember how I figured out this pattern\n\n# Code\n```\nclass Solution:\n    def maximumBinaryString(self, binary: str) -> str:\n        idx = binary.find(\'01\')\n        if idx == -1:\n            return \'1\' * (len(binary) - 1) + binary[-1]\n        n = idx + binary[idx:].count(\'0\')\n        return \'1\' * (n - 1) + \'0\' + \'1\' * (len(binary) - n)\n```
['Python3']