仅做学习笔记,详细请访问代码随想录
● 509. 斐波那契数
● 70. 爬楼梯
● 746. 使用最小花费爬楼梯
class Solution {
public:
int fib(int N) {
if (N <= 1) return N;
int dp[2];
dp[0] = 0;
dp[1] = 1;
for (int i = 2; i <= N; i++) {
int sum = dp[0] + dp[1];
dp[0] = dp[1];
dp[1] = sum;
}
return dp[1];
}
};