由于取反转后字典序最大的值,则从左至右找到第一处为 "0" 的连续区间并将其转换为 "1" 即可

#
# 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可
#
# 
# @param num string字符串 
# @return string字符串
#
class Solution:
    def maxLexicographical(self , num ):
        # write code here
        s = e = -1
        for i, n in enumerate(num):
            if n == "0" and s == -1:
                s = i
            if n == "1" and s != -1:
                e = i
                break
        if s == -1:
            return num
        if e == -1:
            e = len(num)
        return num[:s] + "1" * (e - s) + num[e:]