Skip to content

Commit ad4c0a7

Browse files
committed
climbing stairs
1 parent 6541080 commit ad4c0a7

File tree

1 file changed

+25
-0
lines changed

1 file changed

+25
-0
lines changed
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
/**
2+
ํ’€์ด :
3+
dp๋ฅผ ์ด์šฉํ•˜์—ฌ ์ด์ „ ์นด์šดํŒ… ๊ฐ’์„ ๊ณ„์† ๋”ํ•ด๊ฐ.
4+
5+
๋ณต์žก๋„ ๊ณ„์‚ฐ :
6+
๊ณ„๋‹จ์˜ ์ˆ˜ -> N
7+
์‹œ๊ฐ„ ๋ณต์žก๋„ : O(N)
8+
๊ณต๊ฐ„ ๋ณต์žก๋„ : O(N)
9+
*/
10+
class Solution {
11+
public int climbStairs(int n) {
12+
if(n < 3) return n;
13+
14+
int[] stairs = new int[n];
15+
16+
stairs[0] = 1;
17+
stairs[1] = 2;
18+
19+
for(int i = 2; i < n; i++) {
20+
stairs[i] = stairs[i-1] + stairs[i-2];
21+
}
22+
23+
return stairs[n-1];
24+
}
25+
}

0 commit comments

Comments
ย (0)