您的位置:首页 > 大数据 > 人工智能

leetcode-70-Climbing Stairs

2017-02-20 17:38 399 查看

问题

题目:[Climbing Stairs]

思路

DP,斐波那契数列是转移方程。

代码

class Solution {
public:
int climbStairs(int n) {
if(1==n) return 1;
else if(2==n) return 2;
else{
int f1 = 1;
int f2 = 2;
for(int i = 3; i <= n; ++i){
int t = f1+f2;
f1 = f2;
f2 = t;
}
return f2;
}
}
};
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: