1702. Maximum Binary String After Change

Updated: 2024-03-12
1 min read
[]

On This Page

LeetCode problem 1702

class Solution:
    def maximumBinaryString(self, binary: str) -> str:
        k = binary.find('0')
        if k == -1:
            return binary
        k += binary[k + 1 :].count('0')
        return '1' * k + '0' + '1' * (len(binary) - k - 1)