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 48366a6 commit 8bb51fbCopy full SHA for 8bb51fb
climbing-stairs/eunhwa99.java
@@ -0,0 +1,17 @@
1
+// n=2 (1,1), (2) -> 2 가지
2
+// n=3 (n=2, 1), (n=1, 2) -> 2 + 1 = 3가지
3
+// n=4 (n=3, 1), (n=2, 2) -> 3 + 2 = 5가지
4
+// n=5 (n=4, 1) , (n=3, 2)
5
+// n=k (n=k-1, 1), (n=k-2, 2)
6
+
7
+class Solution {
8
+ public int climbStairs(int n) {
9
+ int[] cntArray = new int[n + 1];
10
+ cntArray[0] = 1;
11
+ cntArray[1] = 1;
12
+ for (int i = 2; i <= n; ++i) { // 시간 복잡도: O(n)
13
+ cntArray[i] = cntArray[i - 1] + cntArray[i - 2];
14
+ }
15
+ return cntArray[n];
16
17
+}
0 commit comments