Skip to content

Commit 236e5ea

Browse files
climbing stairs solution
1 parent f3fe4e6 commit 236e5ea

File tree

1 file changed

+27
-0
lines changed

1 file changed

+27
-0
lines changed

climbing-stairs/jaejeong1.java

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
class SolutionClimbStairs {
2+
3+
public static void main(String[] args) {
4+
SolutionClimbStairs s = new SolutionClimbStairs();
5+
System.out.println(s.climbStairs(3));
6+
}
7+
8+
public int climbStairs(int n) {
9+
if (n == 1) {
10+
return 1;
11+
}
12+
13+
if (n == 2) {
14+
return 2;
15+
}
16+
17+
int[] stairs = new int[n+1];
18+
stairs[1] = 1;
19+
stairs[2] = 2;
20+
21+
for (int i=3; i<=n; i++) {
22+
stairs[i] = stairs[i-1] + stairs[i-2];
23+
}
24+
25+
return stairs[n];
26+
}
27+
}

0 commit comments

Comments
 (0)