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 b43cfb8 commit c497f74Copy full SHA for c497f74
โclimbing-stairs/uraflower.jsโ
@@ -0,0 +1,23 @@
1
+/**
2
+ * ํ ์นธ ๋๋ ๋ ์นธ์ฉ n๊ฐ์ ๊ณ๋จ์ ์ค๋ฅด๋ ๋ฐฉ๋ฒ์ ๊ฐ์ง์๋ฅผ ๋ฐํํ๋ ํจ์
3
+ * @param {number} n
4
+ * @return {number}
5
+ */
6
+const climbStairs = function(n) {
7
+ const steps = Array.from({length: n + 1}).fill(0);
8
+
9
+ for (let i = 1; i <= n; i++) {
10
+ if (i === 1) {
11
+ steps[i] = 1;
12
+ } else if (i === 2) {
13
+ steps[i] = 2;
14
+ } else {
15
+ steps[i] = steps[i-1] + steps[i-2];
16
+ }
17
18
19
+ return steps[n];
20
+};
21
22
+// ์๊ฐ๋ณต์ก๋: O(n)
23
+// ๊ณต๊ฐ๋ณต์ก๋: O(n)
0 commit comments