Climbing Stairs
2015-08-22 09:53
357 查看
题目: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?
思路:我的解题思想是排列组合的思想,看看路面有多少个2步的走法。代码如下:
Each time you can either climb 1 or 2 steps. In how many distinct ways can you climb to the top?
思路:我的解题思想是排列组合的思想,看看路面有多少个2步的走法。代码如下:
class Solution(object): def climbStairs(self, n): """ :type n: int :rtype: int """ count = 1 if n == 1: return 1 num2 = n // 2 i = 1 while i <= num2: tamp = n - i dividend = tamp divisor = 1 #计算被除数 j = 1 while j < i: dividend *= (tamp-j) j += 1 #计算除数 j = 1 while j <= i: divisor *= j j += 1 count += (dividend / divisor) i += 1 return count
相关文章推荐
- JUnit3 结合一个除法的单元测试说明Assert.fail()的用法
- poj 1995 Raising Modulo Numbers 【快速幂 裸题】
- aiSee3 矢量图像文本格式 示例
- POJ 3411 Paid Roads
- LeetCode "Paint House"
- hdu 5316 Magician 2015 Multi-University Training Contest 3
- 关于pkg: /data/local/tmp/com.example.zy.deyijia Failure [INSTALL_FAILED_OLDER_SD问题
- 【LeetCode】(172)Factorial Trailing Zeroes(Easy)
- uva 11168 - Airport(凸包)
- Selenium 高阶应用之WebDriverWait 和 expected_conditions
- Selenium 高阶应用之WebDriverWait 和 expected_conditions
- 2015 Multi-University Training Contest 10 hdu 5411 CRB and Puzzle
- wget+webmin+dns+lamp+openwebmail
- hdu1021Fibonacci Again
- [杂谈]机器学习:数学、概率与人工智能
- Codeforces Gym 100338H High Speed Trains 组合数学+dp+高精度
- ip,email,银行卡号匹配
- 03-树3. Tree Traversals Again (25)将先序遍历和中序遍历转为后序遍历
- main函数的参数(一)
- USACO 2009 Feb Gold 3.Revamping Trails