Skip to content

Commit ab1b00b

Browse files
committed
climbin-stars solution
1 parent d5f8ddc commit ab1b00b

File tree

1 file changed

+23
-0
lines changed

1 file changed

+23
-0
lines changed

climbing-stairs/toychip.java

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
class Solution {
2+
public int climbStairs(int n) {
3+
int[] memo = new int[n + 1];
4+
return recur(n, memo);
5+
}
6+
7+
int recur(int n, int[] memo) {
8+
if (n < 0) {
9+
return 0;
10+
}
11+
12+
if (n == 0) {
13+
return 1;
14+
}
15+
16+
if (memo[n] > 0) {
17+
return memo[n];
18+
}
19+
20+
memo[n] = recur(n - 1, memo) + recur(n - 2, memo);
21+
return memo[n];
22+
}
23+
}

0 commit comments

Comments
 (0)