Skip to content

Commit 33b435b

Browse files
Time: 0 ms (100.00%), Space: 35.6 MB (70.98%) - LeetHub
1 parent ee9170e commit 33b435b

File tree

1 file changed

+19
-0
lines changed

1 file changed

+19
-0
lines changed

climbing-stairs/climbing-stairs.java

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

0 commit comments

Comments
 (0)