设为首页 加入收藏

TOP

LeetCode70――Climbing Stairs
2015-07-20 17:17:52 来源: 作者: 【 】 浏览:3
Tags:LeetCode70 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?

难度系数:

容易

实现

int climbStairs(int n) {
    if (n <= 2) {
        return n;
    } else {
        int *step = new int[n+1];
        step[1] = 1;
        step[2] = 2;
        for (int i = 3; i <= n; ++i) {
            step[i] = step[i-1] + step[i-2];
        }
        int tmp = step[n];
        delete step;
        return tmp;
    }   
}
】【打印繁体】【投稿】【收藏】 【推荐】【举报】【评论】 【关闭】 【返回顶部
分享到: 
上一篇POJ3169(最短路+差分约束) 下一篇leetcode_75_Sort Colors

评论

帐  号: 密码: (新用户注册)
验 证 码:
表  情:
内  容:

·如何理解c语言指针和 (2025-12-27 01:19:11)
·为什么C标准库没有链 (2025-12-27 01:19:08)
·玩转C语言和数据结构 (2025-12-27 01:19:05)
·MySQL 基础入门视频 (2025-12-26 23:20:22)
·小白入门:MySQL超详 (2025-12-26 23:20:19)