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层 ...
随机推荐
- .net线程池内幕
本文通过对.NET4.5的ThreadPool源码的分析讲解揭示.NET线程池的内幕,并总结ThreadPool设计的好与不足. 线程池的作用线程池,顾名思义,线程对象池.Task和TPL都有用到线程 ...
- List集合去重的一种方法
前一段时间们需要对一个List<Model>集合去重,情况是该集合中会出现多个Name属性值相同的,但是其他属性值不同的数据. 在这种情况下,需求要只保留其中一个就好. 我觉得遍历和Has ...
- OpenSAML
一.背景知识: SAML即安全断言标记语言,英文全称是Security Assertion Markup Language.它是一个基于XML的标准,用于在不同的安全域(security domain ...
- 【工业串口和网络软件通讯平台(SuperIO)教程】二.架构和组成部分
1.1 架构结构图 1.1.1 层次示意图 1.1.2 模型对象示意图 1.2 IO管理器 IO管理器是对串口和网络通讯链路的管理.调度.针对串口和网络通讯链路的特点,在IO管 ...
- 接入统计Crash的工具Crashlytics-ios
1. 注册账户 登录网站 https://get.fabric.io/ 来注册新的账户 2. account confirmed之后就出现相应的设置页面,设置你的team的名称 3. 出现页面提示下载 ...
- Web系统开发构架再思考-前后端的完全分离
前言 前后端完全分离其实一直是Web开发人员的梦想,也一直是我的梦想,遥想当年,无论是直接在代码里面输出HTML,还是在HTML里面嵌入各种代码,都不能让人感到满意.期间的痛苦和纠结,我想所有Web开 ...
- iOS开发中<null>的处理
在iOS开发过程中经常需要与服务器进行数据通讯,JSON就是一种常用的高效简洁的数据格式. 问题: 在项目中,一直遇到一个坑的问题,程序在获取某些数据之后莫名崩溃.原因是:由于服务器的数据库中有些字段 ...
- K近邻模型(k-NN)
原理 K最近邻(k-Nearest Neighbor,KNN)分类算法,是一个理论上比较成熟的方法,也是最简单的机器学习算法之一.该方法的思路是:如果一个样本在特征空间中的k个最相似(即特征空间中最邻 ...
- XcodeiOS模拟器安装相关
模拟器下载 注意: Xcode 7 Beta 不支持 iOS 8.4 及之前的 SDK. 现在的Xcode 6.x 似乎只支持iOS 7.0及之后的版本,早期的模拟器运行时不支持新的CoreSimul ...
- android handler传递消息机制
当工作线程给主线程发送消息时,因为主线程是有looper的,所以不需要初始化looper,注意给谁发消息就关联谁的handler,此时用的就是主线程的handler handler会把消息发送到Mes ...