Skip to content

Commit c1256cf

Browse files
authored
Create 70. Climbing Stairs.java
1 parent a452b3b commit c1256cf

File tree

1 file changed

+24
-0
lines changed

1 file changed

+24
-0
lines changed

70. Climbing Stairs.java

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
// Runtime 0ms
2+
// Beats 100.00%
3+
4+
// Memory 40.35MB
5+
// Beats 23.54%
6+
7+
8+
class Solution {
9+
private int[] memo = new int[46];
10+
11+
public int climbStairs(int n) {
12+
if (n <= 0) return 0;
13+
if (n == 1 || n == 2 || n == 3) return n;
14+
15+
if (memo[n] != 0) {
16+
return memo[n];
17+
}
18+
19+
int ways = climbStairs(n - 1) + climbStairs(n - 2);
20+
memo[n] = ways;
21+
22+
return ways;
23+
}
24+
}

0 commit comments

Comments
 (0)