Skip to content

Commit ed2970c

Browse files
authored
Create 70. Climbing Stairs.java
1 parent fecf4d7 commit ed2970c

1 file changed

Lines changed: 14 additions & 0 deletions

File tree

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

0 commit comments

Comments
 (0)