70. Climbing Stairs
# Easy
DP + record
total(n) = total(n-1) + total(n-2)
total(n)
means how many climb ways for n
stairs.
class Solution {
public int climbStairs(int n) {
int[] steps = new int[n+1];
steps[0] = 1;
steps[1] = 1;
if(n == 1) return steps[1];
for(int i = 2; i <= n; i ++) {
steps[i] = steps[i-1] + steps[i-2];
}
return steps[n];
}
}
Last updated
Was this helpful?