Python 3 | Greedy | Explanation
Explanation\n- To get some intuition, make up a couple examples and test it out\n- Soon you will find that:\n\t- The second operation 10 -> 01 will push 0 towar
### Explanation\n- To get some intuition, _**make up a couple examples and test it out**_\n- Soon you will find that:\n\t- The second operation `10` -> `01` will push `0` towards left, e.g.\n\t\t- `1110` -> `1101` -> `1011` -> `0111`\n\t- The first operation make `00000...` to `11111....0` to make string larger\n- What you need to do is to push all zero towards left until they are together\n- **Note** that you don\'t need to push `0` towards left if there is no more `0`, e.g.\n\t- `11100` -> can be changed to `00111` -> `10111`, which is less than the original. Thus, no need to push towards left.\n- So here comes the procedure\n\t- First, keep all leading `1`s as is\n\t- Then, for the rest of string `binary`, make `0` to most left using the second operation (if applicable, i.e. counts of `0` > 0)\n\t\t- Simply count number of `0` and `1` then make all `0`s before `1`s\n\t- After that, change the `0000...` to `111...0`  (if applicable, i.e. counts of `0` > 0)\n\t\t- If there are `zero` `0`s, the result will be `\'1\'*(zero-1) + \'0\'`\n\t- Finally, the result will include\n\t\t- Leading `1`s: `binary[:zero_idx]`, where `zero_idx` is the index of the first `\'0\'`\n\t\t- Possibly updated `0`s: `\'1\'*(zero-1)`, where `zero` is number of `\'0\'`s\n\t\t- Leftover `0` from above update: `\'0\'*min(zero, 1)` or `\'\' if zero <= 0 else \'0\'`\n\t\t- Suffix `1`s: `{\'1\'*one}`, where `one` is number of `\'1\'`s, not including leading `\'1\'`s\n- See more detail from code below\n### Implementation\n```\nclass Solution:\n    def maximumBinaryString(self, binary: str) -> str:\n        zero = binary.count(\'0\')                         # count number of \'0\'\n        zero_idx = binary.index(\'0\') if zero > 0 else 0  # find the index of fist \'0\' if exists\n        one = len(binary) - zero_idx - zero              # count number of \'1\' (not including leading \'1\'s)\n        return f"{binary[:zero_idx]}{\'1\'*(zero-1)}{\'0\'*min(zero, 1)}{\'1\'*one}"\n```
['Greedy', 'Python', 'Python3']