首页 > 其他 > 详细

3月3日(6) Climbing Stairs

时间:2014-03-04 12:22:52      阅读:356      评论:0      收藏:0      [点我收藏+]

原题 Climbing Stairs

求斐波那契数列的第N项,开始想用通项公式求解,其实一个O(n)就搞定了。

bubuko.com,布布扣
class Solution {
public:
    int climbStairs(int n) {
        if (n==0) return 0;
        
        int n1 = 0;
        int n2 = 1;
        
        for (int i=0; i<n; ++i)
        {
            int t = n2;
            n2 = n1 + n2;
            n1 = t; 
        }
        return n2;
    }
};
bubuko.com,布布扣

还是觉得没有ACM难度,继续做吧。

3月3日(6) Climbing Stairs,布布扣,bubuko.com

3月3日(6) Climbing Stairs

原文:http://www.cnblogs.com/seenthewind/p/3579047.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!