Problem: 70. 爬楼梯
复杂度
时间复杂度: O ( n ) O(n) O(n)
Code
class Solution {
public int climbStairs(int n)
{
int[] f = new int[n + 1];
f[0] = 1;
f[1] = 1;
for (int i = 2; i <= n; i++)
f[i] = f[i - 1] + f[i - 2];
return f[n];
}
}
Problem: 70. 爬楼梯
时间复杂度: O ( n ) O(n) O(n)
class Solution {
public int climbStairs(int n)
{
int[] f = new int[n + 1];
f[0] = 1;
f[1] = 1;
for (int i = 2; i <= n; i++)
f[i] = f[i - 1] + f[i - 2];
return f[n];
}
}