LeetCode 70. Climbing Stairs

You are climbing a stair case. It takes n steps to reach to the top.

Each time you can either climb 1 or 2 steps. In how many distinct ways can you climb to the top?

Note: Given n will be a positive integer.

程序代码:

int climbStairs(int n) {
    int TwoStep=1,OneStep=1,i,sum=0;
    if(n==1)
        sum = 1;
    for(i=2;i<=n;i++)
    {
        sum = TwoStep+OneStep;
        TwoStep = OneStep;
        OneStep= sum;
    }
    return sum;
}
全部评论

相关推荐

06-24 19:27
云南大学 Java
点赞 评论 收藏
分享
06-02 15:53
阳光学院 Java
点赞 评论 收藏
分享
不愿透露姓名的神秘牛友
07-08 10:39
一个证都没&nbsp;我能填什么
程序员小白条:别人有,你为什么没有,还是这个道理,社会就是比较,竞争,淘汰,你要安逸,那么就要做好淘汰的准备
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务