-
Notifications
You must be signed in to change notification settings - Fork 0
/
1291.sequential-digits.java
39 lines (35 loc) · 1.06 KB
/
1291.sequential-digits.java
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
class Solution {
public List<Integer> sequentialDigits(int low, int high) {
String l = low+"";
String h = high+"";
// System.out.println(l+" "+h);
List<Integer> res = new ArrayList<Integer>();
int i = 1;
int j= h.length();
int p = 0;
System.out.println(i);
while(i<=9){
p = calcv(low, high, i, i, res, 0, 1);
i++;
}
//calcv(low, high, 6, 6, res, 0, 1);
Collections.sort(res);
return res;
}
public int calcv(int low, int high, int i, int st, List<Integer> res, int val, int thou){
if(val > high || i > 10){
// System.out.println(val+" "+st+" "+thou);
return val%10;
}
// System.out.println(val+" "+st+" ");
if(val >= low && val <= high)
res.add(val);
val = val*10+i;
thou = 10*thou;
if(val > high){
return val%10;
}
return calcv(low,high,i+1, st, res,val,thou);
//calcv(low, high,st+1, st+1, res, 0, 1);
}
}