Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit e045075

Browse files
Added LC 70 java solution (#143)
1 parent 84c1b19 commit e045075

File tree

1 file changed

+29
-0
lines changed

1 file changed

+29
-0
lines changed
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -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+
return memo[step];
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

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /