給定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;
}
暴力破解