LeetCode 70 爬楼梯
fun(n) = fun(n - 1) + fun(n - 2)
int climbStairs(int n){
if (n == 0) return 0;
if (n == 1) return 1;
if (n == 2) return 2;
if (n == 3) return 3;
int arr[n + 1];
arr[1] = 1, arr[2] = 2, arr[3] = 3;
for (int i = 4; i < n + 1; i++) {
arr[i] = arr[i - 1] + arr[i - 2];
}
return arr[n];
}
int climbStairs(int n){
if (n == 0) return 0;
if (n == 1) return 1;
if (n == 2) return 2;
int f2 = 1, f1 = 2, f = 0;
for (int i = 3; i <= n; i++) {
f = f1 + f2;
f2 = f1;
f1 = f;
}
return f;
}