Skip to content

Commit f7093c5

Browse files
committed
[week3] solve 70. Climbing Stairs
1 parent f872aad commit f7093c5

File tree

1 file changed

+20
-0
lines changed

1 file changed

+20
-0
lines changed

climbing-stairs/bky373.java

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
class Solution {
2+
3+
public int climbStairs(int n) {
4+
int[] ans = new int[n + 1];
5+
if (n <= 2) {
6+
return n;
7+
}
8+
ans[1] = 1;
9+
ans[2] = 2;
10+
11+
for (int i = 3; i < n + 1; i++) {
12+
ans[i] = ans[i - 1] + ans[i - 2];
13+
}
14+
return ans[n];
15+
}
16+
}
17+
/**
18+
* TC: O(N)
19+
* SC: O(N)
20+
*/

0 commit comments

Comments
 (0)