Skip to content

Commit d24f775

Browse files
authored
Merge pull request #52 from khushi200701/pr2
climbing-stairs-leetcode
2 parents 6353c4b + 48c08c6 commit d24f775

File tree

1 file changed

+22
-0
lines changed

1 file changed

+22
-0
lines changed

climbing-stairs.java

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

0 commit comments

Comments
 (0)