Skip to content

Commit 6068069

Browse files
committed
add: climbing stairs solution
1 parent 78c1fea commit 6068069

File tree

1 file changed

+19
-0
lines changed

1 file changed

+19
-0
lines changed

climbing-stairs/JEONGBEOMKO.java

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
package week02.Climbing_stairs;
2+
3+
class Solution {
4+
public int climbStairs(int n) {
5+
6+
if (n == 1 || n == 2) {
7+
return n;
8+
}
9+
10+
int[] cases = new int[n + 1];
11+
cases[1] = 1;
12+
cases[2] = 2;
13+
for (int i = 3; i <= n; i++) {
14+
cases[i] = cases[i - 1] + cases[i - 2];
15+
}
16+
17+
return cases[n];
18+
}
19+
}

0 commit comments

Comments
 (0)