Skip to content

Commit 0891975

Browse files
committed
add solution for climbing-stairs
1 parent ea282ec commit 0891975

File tree

1 file changed

+16
-0
lines changed

1 file changed

+16
-0
lines changed

climbing-stairs/Ujoonnee.java

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

0 commit comments

Comments
 (0)