若是一個數字十進制表達時,不存在連續兩位數字相等,則稱之爲「不重複數」。例如,105,1234和12121都是「不重複數」,而11,100和 1225不算。給定一個long類型數字A,返回大於A的最小「不重複數」。 下面是幾個測試用例 java
Examples:
0) 54
returns: 56
大於54的最小數字是55,但55不是「不重複數」。下一個數字是56,它知足條件。
1) 10
returns: 12
2) 9
returns: 10
3) 98
returns: 101
99和100都不是「不重複數」, 101是。
4) 21099
returns: 21201
5) 99123
returns: 101010
6) 1134567
returns: 1201010 測試
public class GetNum { public static void main(String[] args) { System.out.println(getNumFunc(-1134567)); } public static int getNumFunc(int i) { boolean flag = true; int j = 0; while (flag) { j = Math.abs(++i); int temp1 = j % 10; int temp2 = 0; boolean flag2 = true; while (j > 0) { temp2 = temp1; j = j / 10; temp1 = j % 10; if (temp1 == temp2) { flag2 = false; } } if (flag2) { flag = false; } } return i; } }Output: -1098989