- Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDecreasingNumber.java
More file actions
Latest commit
49 lines (38 loc) · 1.03 KB
/
Copy pathDecreasingNumber.java
File metadata and controls
49 lines (38 loc) · 1.03 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
importjava.io.InputStreamReader;
importjava.util.ArrayList;
importjava.util.Collections;
importjava.io.BufferedReader;
importjava.io.IOException;
publicclassDecreasingNumber {
publicstaticvoidmain(String[] args) {
try {
newExploringDecreasingNumber();
}catch(IOExceptione) {
e.printStackTrace();
}
}
}
classExploringDecreasingNumber{
privateArrayList<Long> list = newArrayList<>();
publicExploringDecreasingNumber() throwsIOException {
intbrNumber = Integer.parseInt(newBufferedReader(newInputStreamReader(System.in)).readLine());
if(brNumber == 0) System.out.println("0");
elseif(brNumber>1022) System.out.println("-1");
else {
for(longi = 0; i<10; i++) {
SearchDecreasingNumber(i, 1);
}
Collections.sort(list);
System.out.println(list.get(brNumber));
}
}
publicvoidSearchDecreasingNumber(longnumber, intdigit) {
if(digit>10)return;
list.add(number);
for(inti = 0; i<10; i++) {
if(number%10>i) {
SearchDecreasingNumber((number*10)+i, digit+1);
}
}
}
}