把6替换成9,遍历即可,主要是java对字符串的操作
class Solution {
public int maximum69Number (int num) {
//String str = String.valueOf(num);
//StringBuilder st = new StringBuilder(str);
StringBuilder str = new StringBuilder(String.valueOf(num));
for(int i=0;i<str.length();i++){
if(str.charAt(i)=='6'){
str.setCharAt(i,'9');
break;
}
}
return Integer.parseInt(str.toString());
}
}