July 28, 2015

Problem statement:

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?

The problem is most popular question in the algorithm, so I do like to spend time to find out all sorts of solution, and get myself comfortable to all kinds of ideas,

and figure out which one is best, and all concerns we can have in the discussion of climbing stairs:

1. Recursion solution vs. DP problem solution (Dynamic Programming solution)

2. Time complexity solution: O(2^n) vs O(n) solution

3. The space O(N) vs O(1), in other words: array of N or 2 variable, and another tmp variable

4. The base case discussion: f(0) = 1 or f(0) =1, math question?

5. Math formula - closed form solution vs DP problem solution

6. Use Memoization DP vs. no memoization DP

7. Programming skills, how to make code easy to follow, more readable, more abstract.

The investment of time on the problem is well done. Go over 16 implementation one by one using C# programming language.

C# code:

 

https://github.com/jianminchen/climbingStairs/blob/master/climbingStairs.cs

其实, 我觉得题目越容易, 越值得投入时间去学习; 看看大家有没有不同的理解, 打开思路; 如果自己没有训练过这道题, 可能会紧张;

即使训练过, 但是, 有的想法, 可能自己从来没有思考过, 一时还不能判断好坏, 想不出来, 但是, 多看网上的博客, 向每一个人取取经. 谦虚, 才能有提高.

我编网站后台, C#程序自己写; 自己训练的题目太少; 这次选择用Leetcode来提高C#编程, 又可以提高算法和数据结构的知识, 网站后台靠

平时训练. 训练的水平, 就是自己编程的水平.

Leetcode: climbing stairs的更多相关文章

  1. [LeetCode] Climbing Stairs 爬梯子问题

    You are climbing a stair case. It takes n steps to reach to the top. Each time you can either climb ...

  2. [LeetCode] Climbing Stairs (Sequence DP)

    Climbing Stairs https://oj.leetcode.com/problems/climbing-stairs/ You are climbing a stair case. It ...

  3. LeetCode——Climbing Stairs

    You are climbing a stair case. It takes n steps to reach to the top. Each time you can either climb ...

  4. LeetCode:Climbing Stairs(编程之美2.9-斐波那契数列)

    题目链接 You are climbing a stair case. It takes n steps to reach to the top. Each time you can either c ...

  5. [Leetcode] climbing stairs 爬楼梯

    You are climbing a stair case. It takes n steps to reach to the top. Each time you can either climb ...

  6. [LeetCode] Climbing Stairs 斐波那契数列

    You are climbing a stair case. It takes n steps to reach to the top. Each time you can either climb ...

  7. leetcode Climbing Stairs python

    class Solution(object): def climbStairs(self, n): """ :type n: int :rtype: int " ...

  8. [LeetCode] Min Cost Climbing Stairs 爬楼梯的最小损失

    On a staircase, the i-th step has some non-negative cost cost[i] assigned (0 indexed). Once you pay ...

  9. Min Cost Climbing Stairs - LeetCode

    目录 题目链接 注意点 解法 小结 题目链接 Min Cost Climbing Stairs - LeetCode 注意点 注意边界条件 解法 解法一:这道题也是一道dp题.dp[i]表示爬到第i层 ...

随机推荐

  1. .NET Task揭秘(一)

    Task为.NET提供了基于任务的异步模式,它不是线程,它运行在线程池的线程上.本着开源的精神, 本文以解读基于.NET4.5 Task源码的方式来揭秘Task的实现原理.   Task的创建 Tas ...

  2. compilation与编译

    关于本配置节的内容不算多,但关于ASP.NET编译的内容还是有一点的,鄙人认为只是了解一下即可,主要影响到部署. 在 App_Code 文件夹中使用多种编程语言 因为 App_Code 文件夹中的源代 ...

  3. 【转】mysql_fetch_row , mysql_fetch_array , mysql_fetch_assoc 的区别

    <?php $link = mysql_connect('localhost', 'root', ”); mysql_select_db('abc', $link); $sql = “selec ...

  4. ABP导航源码分析

    按步骤看: 1,在Global.asax中执行: base.Application_Start(sender, e); 2,在AbpWebApplication类的Application_Start( ...

  5. S1java基础学习笔记

    第一章  Java基础 程序目标:减轻现实生活中一类人的工作量,提高工作效率. 学员最终可以书写系统: 超市管理系统,POS机系统等 入库单 销售单 01.课程重点 五大重点: 01.分支(选择)结构 ...

  6. CSS3中flexbox如何实现水平垂直居中和三列等高布局

    最近这些天都在弥补css以及css3的基础知识,在打开网页的时候,发现了火狐默认首页上有这样一个东西.

  7. 学习zepto.js(对象方法)[6]

    first: 获取当前对象集合中的第一个dom元素. $("div").first(); // 返回第一个div对象(zepto对象) //相当于$("div" ...

  8. Android Fragment使用(一) 基础篇 温故知新

    Fragment使用的基本知识点总结, 包括Fragment的添加, 参数传递和通信, 生命周期和各种操作. Fragment使用基础 Fragment添加 方法一: 布局里的标签 标识符: tag, ...

  9. IOS开发基础知识--碎片23

    1:关于UITableView中关于行重复加载的问题 在Cell里重写prepareForReuse,对一些控件进行清空: 比较简单: -(void)prepareForReuse{ [super p ...

  10. 手机APP创建桌面快捷方式

    预览: 需要权限:   <uses-permission android:name="com.android.launcher.permission.INSTALL_SHORTCUT& ...