import java.util.*;
public class Solution {
public String maxLexicographical (String num) {
// 预处理
if (num.length() == 0) return "";
// 初始化
char[] bits = num.toCharArray();
// 遍历数组
int index = 0;
// 找到第一个0的位置
while (index < bits.length && bits[index] != '0') {
index++;
}
// 从当前位置起将所有连续的0变成1
while (index < bits.length && bits[index] == '0') {
bits[index++] = '1';
}
// 数组遍历完成
// 将数组转为字符串后返回结果
return new String(bits);
}
}



京公网安备 11010502036488号