---
# System prepended metadata

title: 1702. Maximum Binary String After Change
tags: [Leetcode, Medium, Greedy]

---

# 1702. Maximum Binary String After Change
###### tags: `Leetcode` `Medium` `Greedy`
Link: https://leetcode.com/problems/maximum-binary-string-after-change/description/
## 思路
思路参考[这里](https://leetcode.com/problems/maximum-binary-string-after-change/solutions/987335/java-c-python-solution-with-explanation/)
We don't need touch the starting 1s, they are already good.

For the rest part,
we continually take operation 2,
making the string like 00...00011...11

Then we continually take operation 1,
making the string like 11...11011...11.
## Code
```python=
class Solution:
    def maximumBinaryString(self, s):
        if '0' not in s: return s
        k, n = s.count('1', s.find('0')), len(s)
        return '1' * (n - k - 1) + '0' + '1' * k
```