首页 > 代码库 > LeetCode --- Climbing Stairs

LeetCode --- Climbing Stairs

题目链接

简单递推

附上代码:

 1 class Solution {
 2 public:
 3     int climbStairs(int n) {
 4         int f0 = 1, f1 = 1, f2 = 1;
 5         for (int i = 2; i <= n; i++) {
 6             f2 = f0 + f1;
 7             swap(f0, f1);
 8             f1 = f2;
 9         }
10         return f2;
11     }
12 };