We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 84c1b19 commit e045075Copy full SHA for e045075
Algorithms/Easy/70_ClimbingStairs/Solution.java
@@ -0,0 +1,29 @@
1
+class Solution {
2
+ int n;
3
+ int[] memo = new int[50];
4
+
5
+ private int solve(int step) {
6
+ if (step == n) {
7
+ return 1;
8
+ } else if (step > n) {
9
+ return 0;
10
+ } else if (memo[step] != -1) {
11
+ return memo[step];
12
+ } else {
13
+ memo[step] = solve(step + 1) + solve(step + 2);
14
15
16
+ }
17
18
19
20
+ public int climbStairs(int n) {
21
+ this.n = n;
22
23
+ for (int i = 0; i < 50; i++) {
24
+ memo[i] = -1;
25
26
27
+ return solve(0);
28
29
+}
0 commit comments