-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathUniqueNumber.java
More file actions
43 lines (39 loc) · 1.19 KB
/
UniqueNumber.java
File metadata and controls
43 lines (39 loc) · 1.19 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
43
/**
* Created by MalhotR1 on 05/17/2017.
*/
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.IOException;
import java.util.ArrayList;
public class UniqueNumber {
public static void main(String[] args) throws IOException {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
int T = Integer.parseInt(br.readLine().trim());
for (int t = 0; t < T; t++) {
String[] in = br.readLine().trim().split(" ");
int start = Integer.parseInt(in[0]);
int end = Integer.parseInt(in[1]);
boolean unique = false;
for (int i = start; i <= end ; i++) {
unique = checkUnique(i);
if (unique) System.out.print(i + " ");
unique = false;
}
}
}
private static boolean checkUnique(int i) {
int[] digits = new int[4];
int j = 0;
while (i > 0) {
digits[j] = (i % 10);
int k = j-1;
while (k >= 0) {
if (digits[k] == digits[j]) return false;
k--;
}
i /= 10;
j++;
}
return true;
}
}