Skip to content

Commit 4662d97

Browse files
climbing stairs solution
1 parent f3fe4e6 commit 4662d97

File tree

1 file changed

+22
-0
lines changed

1 file changed

+22
-0
lines changed

climbing-stairs/jaejeong1.java

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

0 commit comments

Comments
 (0)