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 9192ae9 commit 5b8aa27Copy full SHA for 5b8aa27
โclimbing-stairs/EcoFriendlyAppleSu.ktโ
@@ -0,0 +1,24 @@
1
+package leetcode_study
2
+
3
+/**
4
+ * ๊ณ๋จ์ ์ฌ๋ผ๊ฐ ์ ์๋ ๊ฒฝ์ฐ์ ์ ๊ตฌํ๋ ๋ฐฉ๋ฒ
5
+ * ์๊ฐ ๋ณต์ก๋: O(n)
6
+ * -> ์ฃผ์ด์ง ํ์ ๋งํผ ๋ฐ๋ณต ์งํ
7
+ * ๊ณต๊ฐ ๋ณต์ก๋: O(k)
8
+ * -> ์ฃผ์ด์ง ๊ณ๋จ ์ ๋งํผ ํ์๋ฅผ ์ ์ฅํ ๊ณต๊ฐ ํ์
9
+ */
10
+fun climbStairs(n: Int): Int {
11
+ val step = IntArray(n+1)
12
13
+ if (n == 1) {
14
+ return 1
15
+ }
16
+ step[1] = 1
17
+ step[2] = 2
18
19
+ for (i in 3 until step.size) {
20
+ step[i] = step[i-1] + step[i-2]
21
22
23
+ return step[n]
24
+}
0 commit comments