70.Climbing Stairs

class Solution {
public:
    int climbStairs(int n) {
        if (n == 1)
            return 1;
        int first = 1;
        int second = 2;
        for(int i = 3; i < n+1; i++){
            int third = first + second;
            first = second;
            second = third;
        }
        return second;
    }
};
posted @ 2019-04-09 10:59  JohnRed  阅读(81)  评论(0编辑  收藏  举报