力扣—climbing stairs(爬楼梯) python实现
题目描述:
中文:
假设你正在爬楼梯。需要 n 阶你才能到达楼顶。
每次你可以爬 1 或 2 个台阶。你有多少种不同的方法可以爬到楼顶呢?
注意:给定 n 是一个正整数。
英文:
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?
Note: Given n will be a positive integer.
class Solution(object):
def climbStairs(self, n):
"""
:type n: int
:rtype: int
"""
dp = [1 for i in range(n+1)]
for i in range(2, n+1):
dp[i] = dp[i-1] + dp[i-2]
return dp[n]
题目来源:力扣
力扣—climbing stairs(爬楼梯) python实现的更多相关文章
- [LeetCode] 70. Climbing Stairs 爬楼梯
You are climbing a stair case. It takes n steps to reach to the top. Each time you can either climb ...
- [LeetCode] 70. Climbing Stairs 爬楼梯问题
You are climbing a stair case. It takes n steps to reach to the top. Each time you can either climb ...
- [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 ...
- climbing stairs(爬楼梯)(动态规划)
You are climbing a stair case. It takes n steps to reach to the top. Each time you can either climb ...
- [LeetCode] 746. Min Cost Climbing Stairs 爬楼梯的最小损失
On a staircase, the i-th step has some non-negative cost cost[i] assigned (0 indexed). Once you pay ...
- Climbing Stairs爬楼梯——动态规划
题目描写叙述: 初阶:有n层的台阶,一開始你站在第0层,每次能够爬两层或者一层. 请问爬到第n层有多少种不同的方法? 进阶:假设每次能够爬两层.和倒退一层,同一个位置不能反复走,请问爬到第n层有多少种 ...
- LeetCode 70. Climbing Stairs爬楼梯 (C++)
题目: You are climbing a stair case. It takes n steps to reach to the top. Each time you can either cl ...
- [leetcode]70. 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 ...
随机推荐
- Go 迭代切片
迭代切片有两种方式: 1. 使用 for range 迭代切片 // 其长度和容量都是 4 个元素 slice := [], , , } // 迭代每一个元素,并显示其值 for index, v ...
- bzoj4922 [Lydsy1706月赛]Karp-de-Chant Number 贪心+背包
题目传送门 https://lydsy.com/JudgeOnline/problem.php?id=4922 题解 记录每一个串的没有匹配的右括号 \()\) 的数量为 \(a_i\),为匹配的左括 ...
- ARGB色彩模式
看到#ff ff ff 00 00这种 就是啦 .开头两位表示透明度.
- CSS中的flex布局
1.flex 布局的概念 Flex是Flexible Box的缩写,意为"弹性布局",用来为盒状模型提供最大的灵活性.任何一个容器都可以指定为 Flex 布局,行内元素也可以通过 ...
- Word中页码及目录、参考文献的制做方法
1.页码从正文开始 1.要想从哪里显示第一页,就在这页的前一页的最后一行最后的地方,插入分隔符---下一页2.然后在你想显示第一页的那一页双击页脚处,点击取消掉“链接到前一条页眉”.(这是为了取消原来 ...
- 汇编 “ program has no starting address ”解决方法
- oracle11g笔记
安装 #!/bin/bash #安装oracle110203 pageDir="/opt/tools/oracle" bdFile="/tmp/bdFile.txt&qu ...
- qbxt Day2 on 19-7-25
qbxt Day2 on 19-7-25 --TGZCBY 上午 1. 矩阵乘法在图论上的应用 有的时候图论的转移方程可以用dp的方式转移 特别是两个数的乘积求和的时候 比如邻接矩阵中f[i][j]表 ...
- Problem accessing /jenkins/. Reason:
这是一个Jenkins的Bug.临时解决方法是:在浏览器中手工输入:http://<ip>:<port>.不要访问"/jenkins"这个路径.
- mysql null 值查询问题
我在开发公司内部的一个项目时遇到一个问题:select student_quality_id from STUDENT_QUALITY where mark_status=0 and batch_st ...