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 2695f42 commit fdd4d40Copy full SHA for fdd4d40
βclimbing-stairs/flynn.mdβ
@@ -0,0 +1,40 @@
1
+## Description
2
+
3
+λ€μ΄λλ―Ή νλ‘κ·Έλλ°μ μ΄μ©νμ¬ ν μ μμ΅λλ€.
4
5
+μλμ κ°μ΄ `memo` λ°°μ΄μ μ μνμ λ,
6
7
+```
8
+memo[0] = 1
9
+memo[1] = 1
10
+memo[i] = distinct ways to climb to the i-th stair
11
12
13
+λ€μκ³Ό κ°μ μ νμμ΄ μ±λ¦½ν©λλ€.
14
15
16
+memo[i] = memo[i - 2] + memo[i - 1] (i > 1)
17
18
19
+## Big-O
20
21
+Time complexity: O(N)
22
23
+Space complexity: O(N)
24
25
+---
26
27
+```cpp
28
+class Solution {
29
+public:
30
+ int climbStairs(int n) {
31
+ vector<int> memo(2, 1);
32
33
+ for (int i = 2; i <= n; i++) {
34
+ memo.push_back(memo[i - 1] + memo[i - 2]);
35
+ }
36
37
+ return memo[n];
38
39
+};
40
0 commit comments