-
Notifications
You must be signed in to change notification settings - Fork 92
/
Stair_Paths.java
46 lines (33 loc) · 1.07 KB
/
Stair_Paths.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
40
41
42
43
44
45
46
import java.io.*;
import java.util.*;
public class Main {
public static void main(String[] args) throws Exception {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
int n = Integer.parseInt(br.readLine());
ArrayList<String> paths = getStairPaths(n);
System.out.println(paths);
}
public static ArrayList<String> getStairPaths(int n) {
if(n <= 0){
ArrayList<String> bres = new ArrayList<>();
if(n == 0){
bres.add("");
}
return bres;
}
ArrayList<String> rres1 = getStairPaths(n - 1);
ArrayList<String> rres2 = getStairPaths(n - 2);
ArrayList<String> rres3 = getStairPaths(n - 3);
ArrayList<String> mres = new ArrayList<>();
for(String rstr: rres1){
mres.add(1 + rstr);
}
for(String rstr: rres2){
mres.add(2 + rstr);
}
for(String rstr: rres3){
mres.add(3 + rstr);
}
return mres;
}
}