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 34a6520 commit 3178771Copy full SHA for 3178771
climbing-stairs/samcho0608.java
@@ -0,0 +1,21 @@
1
+class Solution {
2
+ // Problem:
3
+ // * can take 1 or 2 steps
4
+ // * return: how many distinct ways to climb to the top(n)
5
+ // Solution:
6
+ // * Time Complexity: O(N)
7
+ // * due to memoization(DP)
8
+ // * Space Complexity: O(N)
9
+ public int climbStairs(int n) {
10
+ // memo[i] = distinct steps to reach ith step
11
+ int[] memo = new int[n + 1];
12
+ memo[0] = 1;
13
+ memo[1] = 1;
14
+
15
+ for(int i = 2; i < n+1; i++) {
16
+ memo[i] = memo[i-1] + memo[i-2];
17
+ }
18
19
+ return memo[n];
20
21
+}
0 commit comments