Skip to content

Commit 2ac98ae

Browse files
committed
climbing stairs
1 parent 64c2bdf commit 2ac98ae

File tree

1 file changed

+18
-0
lines changed

1 file changed

+18
-0
lines changed

climbing-stairs/hjeomdev.java

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
class Solution {
2+
List<Integer> list = new ArrayList<>();
3+
public int climbStairs(int n) {
4+
list.add(0);
5+
list.add(1);
6+
list.add(2);
7+
return step(n);
8+
}
9+
10+
public int step(int n) {
11+
if (list.size() > n && list.get(n) != null) {
12+
return list.get(n);
13+
}
14+
int result = step(n - 1) + step(n - 2);
15+
list.add(result);
16+
return result;
17+
}
18+
}

0 commit comments

Comments
 (0)