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#编程, 又可以提高算法和数据结构的知识, 网站后台靠

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

转载于:https://www.cnblogs.com/juliachenOnSoftware/p/4692033.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值