Skip to content

Commit 536fe6a

Browse files
committed
feat: climbing-stairs solution
1 parent 8272389 commit 536fe6a

File tree

1 file changed

+16
-0
lines changed

1 file changed

+16
-0
lines changed

climbing-stairs/sm9171.java

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

0 commit comments

Comments
 (0)