We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent f3fe4e6 commit 236e5eaCopy full SHA for 236e5ea
climbing-stairs/jaejeong1.java
@@ -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