Skip to content

Commit 5b8aa27

Browse files
author
แ„‹แ…ตแ„‹แ…งแ†ซแ„‰แ…ฎ
committed
Climbing Stairs
1 parent 9192ae9 commit 5b8aa27

File tree

1 file changed

+24
-0
lines changed

1 file changed

+24
-0
lines changed
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -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

Comments
ย (0)