Leetcode: climbing stairs
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的更多相关文章
- [LeetCode] Climbing Stairs 爬梯子问题
You are climbing a stair case. It takes n steps to reach to the top. Each time you can either climb ...
- [LeetCode] Climbing Stairs (Sequence DP)
Climbing Stairs https://oj.leetcode.com/problems/climbing-stairs/ You are climbing a stair case. It ...
- LeetCode——Climbing Stairs
You are climbing a stair case. It takes n steps to reach to the top. Each time you can either climb ...
- 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 ...
- [Leetcode] climbing stairs 爬楼梯
You are climbing a stair case. It takes n steps to reach to the top. Each time you can either climb ...
- [LeetCode] Climbing Stairs 斐波那契数列
You are climbing a stair case. It takes n steps to reach to the top. Each time you can either climb ...
- leetcode Climbing Stairs python
class Solution(object): def climbStairs(self, n): """ :type n: int :rtype: int " ...
- [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 ...
- Min Cost Climbing Stairs - LeetCode
目录 题目链接 注意点 解法 小结 题目链接 Min Cost Climbing Stairs - LeetCode 注意点 注意边界条件 解法 解法一:这道题也是一道dp题.dp[i]表示爬到第i层 ...
随机推荐
- Visual Studio.NET单选题
在Visual Studio.NET窗口中,在__________窗口中可以察看当前项目的类和类型的层次信息. A. 解决方案资源管理器 B. 类视图 C. 资源视图 D. 属性 在线答题:http ...
- 各种类型转换为字符串类型(ToString())
更详细请参考:http://blog.csdn.net/wanzhuan2010/article/details/8478904 // C 货币 2.5.ToString("C") ...
- ATM跨行取款的清算方式
ATM跨行取款和POS机是类似的,因为没有商户参与,所以不需要收单清算,过程更为简单. 回到文章最开头的例子:你拿着一张工行卡去建行的ATM取了100元,这个跨行业务在CNAPS体系中的过程如下: 你 ...
- ZKUI中文编码以及以docker方式运行的问题
*:first-child { margin-top: 0 !important; } body>*:last-child { margin-bottom: 0 !important; } /* ...
- javascript函数调用的各种方法!!
在JavaScript中一共有下面4种调用方式: (1) 基本函数调用 (2)方法调用 (3)构造器调用 (4)通过call()和apply()进行调用 1. 基本函数调用 普通函数调用模式,如: J ...
- 自定义UITableView各种函数
转自:http://blog.sina.com.cn/s/blog_7e3132ca0100wyls.html 在XCode对应头文件中修改该类所继承的父类: 在对应的.m文件中添加如下代码: 这样就 ...
- MyEclipse使用心得:集成和使用Maven的方法
MyEclipse下载:http://www.myeclipsecn.com/download/ 第一步:下载和安装 1.官网下载Maven:http://maven.apache.org/downl ...
- 使用ArcGIS JavaScript API 3.18 加载天地图
对于中国开发者在创建GIS应用的时候,往往比较头疼的是底图资源的缺乏.其实国家测绘地信局就提供一个很好的免费资源:天地图.使用ArcGIS API的开发人员可以直接利用该资源作为地图应用的底图. Ar ...
- ViewPager+GridView实现横向滑动 仿大众点评
先看演示效果: 1 ViewPager类提供了多界面切换的新效果. 新效果有如下特征: [1] 当前显示一组界面中的其中一个界面. [2] 当用户通过左右滑动界面时,当前的屏幕显示当前界面和下一个界 ...
- Android Studio 2.2.2导入Eclipse中创建的项目
最近随视频教程学习Android,原本都是用Adt写Android程序,中途教程换成了Android Studio,于是我自己下了android studio 2.2.2安装好,并下载好sdk,也跟着 ...