Skip to content

Commit 3f83e97

Browse files
committed
add solution for climbing-stairs
1 parent 887eb11 commit 3f83e97

1 file changed

Lines changed: 27 additions & 0 deletions

File tree

climbing-stairs/Hyeri1ee.java

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
import java.util.*;
2+
3+
class Solution {
4+
public int climbStairs(int n) {
5+
int[] steps = new int[n+1];
6+
if (n == 1) return 1;
7+
if (n == 2) return 2;
8+
if (n == 3) return 3;
9+
steps[1] = 1; steps[2] = 2;//2, 1+1
10+
steps[3] = 3;
11+
for(int i = 4;i < n+1; i++){
12+
steps[i] = steps[i-1] + steps[i-2];
13+
}
14+
/*
15+
steps[4] =
16+
1+1+1+1
17+
1+2+1
18+
2+2
19+
2+1+1
20+
1+1+2
21+
*/
22+
23+
return steps[n];
24+
25+
26+
}
27+
}

0 commit comments

Comments
 (0)