Skip to content

Commit 7aef46c

Browse files
committed
feat(leetcode/70): Climbing Stairs (Easy)
1 parent 6ed60b9 commit 7aef46c

File tree

1 file changed

+20
-2
lines changed

1 file changed

+20
-2
lines changed

climbing-stairs/renovizee.java

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,35 @@
11

22

3+
34
// tag renovizee 2week
45
// https://github.com/DaleStudy/leetcode-study/issues/230
56
// https://leetcode.com/problems/climbing-stairs/ #70 #Easy
67
class Solution {
7-
// Solv1 :
8+
// Solv1
89
// 시간복잡도 : O(n)
910
// 공간복잡도 : O(n)
1011
public int climbStairs(int n) {
12+
int[] dp = new int[]{1, 2};
13+
14+
if (n == dp[0]) {
15+
return dp[0];
16+
}
17+
18+
if (n == dp[1]) {
19+
return dp[1];
20+
}
21+
22+
for (int i = 3; i <= n; i++) {
23+
int nextWayCount = dp[0] + dp[1];
24+
dp[0] = dp[1];
25+
dp[1] = nextWayCount;
26+
}
27+
28+
return dp[1];
1129

1230
}
1331
}
1432
//-------------------------------------------------------------------------------------------------------------
1533
// Java 문법 피드백
16-
//
34+
// 1) Math.pow(2, 3) 2의 3승.
1735
//-------------------------------------------------------------------------------------------------------------

0 commit comments

Comments
 (0)