设为首页 加入收藏

TOP

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

评论

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

·Redis压力测试实战 - (2025-12-27 09:20:24)
·高并发一上来,微服 (2025-12-27 09:20:21)
·Redis 高可用架构深 (2025-12-27 09:20:18)
·Linux 系统监控 的完 (2025-12-27 08:52:29)
·一口气总结,25 个 L (2025-12-27 08:52:27)