给定N是一个正整数,求比N大的最小“不重复数”,这里的不重复是指没有两个相等的相邻位,如1102中的11是相等的两个相邻位故不是不重复数,而12301是不重复数。
public static boolean isRep(int n){
if(n < 0){
return false;
}
String str = String.valueOf(n);
char last = str.charAt(0);
for(int i=1;i<str.length();i++){
if(last == str.charAt(i)){
return true;
}else{
last = str.charAt(i);
}
}
return false;
}
public static int minNotRep(int n){
if(n<0){return 0;}
int result = n+1;
while(isRep(result)){
++result;
}
return result;
}
暴力破解