题解 | #二进制取反#
二进制取反
https://www.nowcoder.com/practice/4ca47baf4d5f4417afc0f99d6efc7d42
import java.util.*; public class Solution { /** * 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可 * * * @param num string字符串 * @return string字符串 */ public String maxLexicographical (String num) { // write code here char[] str = num.toCharArray(); for (int i = 0; i < str.length; i++){ if (str[i] == '0'){ while(i < str.length && str[i] == '0'){ str[i++] = '1'; } break; } } num = ""; for (int i = 0; i < str.length; i++){ num += str[i]; } return num; } }