leetcode-easy-dynamic-70 Climbing Stairs
mycode 65%
class Solution(object):
def climbStairs(self, n):
"""
:type n: int
:rtype: int
"""
if n == 1:
return 1
if n == 2:
return 2
i = 3
dic = {1:1,2:2}
while i < n+1:
dic[i] = dic[i-2] + dic[i-1]
i += 1
return dic[n]
下面这个会超时。。。
class Solution(object):
def climbStairs(self, n):
"""
:type n: int
:rtype: int
"""
if n == 1:
return 1
if n == 2:
return 2
return self.climbStairs(n-1) + self.climbStairs(n-2)
参考
class Solution(object):
def climbStairs(self, n):
a, b = 1, 1
for i in range(n):
a, b = b, a + b
return a
leetcode-easy-dynamic-70 Climbing Stairs的更多相关文章
- LeetCode练题——70. Climbing Stairs
1.题目 70. Climbing Stairs——Easy You are climbing a stair case. It takes n steps to reach to the top. ...
- [LeetCode&Python] Problem 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❤python】70. Climbing Stairs
#Method1:动态规划##当有n个台阶时,可供选择的走法可以分两类:###1,先跨一阶再跨完剩下n-1阶:###2,先跨2阶再跨完剩下n-2阶.###所以n阶的不同走法的数目是n-1阶和n-2阶的 ...
- Leetcode之70. Climbing Stairs Easy
Leetcode 70 Climbing Stairs Easy https://leetcode.com/problems/climbing-stairs/ You are climbing a s ...
- [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 746. Min Cost Climbing Stairs(easy understanding dp solution)
leetcode 746. Min Cost Climbing Stairs(easy understanding dp solution) On a staircase, the i-th step ...
- 42. leetcode 70. Climbing Stairs
70. Climbing Stairs You are climbing a stair case. It takes n steps to reach to the top. Each time y ...
- Leetcode#70. Climbing Stairs(爬楼梯)
题目描述 假设你正在爬楼梯.需要 n 阶你才能到达楼顶. 每次你可以爬 1 或 2 个台阶.你有多少种不同的方法可以爬到楼顶呢? 注意:给定 n 是一个正整数. 示例 1: 输入: 2 输出: 2 解 ...
- LN : leetcode 70 Climbing Stairs
lc 70 Climbing Stairs 70 Climbing Stairs You are climbing a stair case. It takes n steps to reach to ...
- 刷题70. Climbing Stairs
一.题目说明 题目70. Climbing Stairs,爬台阶(楼梯),一次可以爬1.2个台阶,n层的台阶有几种爬法.难度是Easy! 二.我的解答 类似的题目做过,问题就变得非常简单.首先用递归方 ...
随机推荐
- 转换byte(十进制)为图形(大小写字母,符号)
/** * 转换byte(十进制)为字母 */ public static String ByteToLetter (byte[] chars) { String Letter = "&qu ...
- ccs之经典布局(一)(水平垂直居中)
经典的css布局有以下几种,下面分别用不同的方法进行实现且进行对比. 一.水平居中 水平居中布局指的是当前元素在父级元素的容器中,水平方向上显示的是居中的,有以下几种方式来完成布局: 1.margin ...
- Elasticsearch 7.4.0官方文档操作
官方文档地址 https://www.elastic.co/guide/en/elasticsearch/reference/current/index.html 1.0.0 设置Elasticsea ...
- 使用ELK进行日志分析
0x01 前言: 前段时间做应急,总是需要溯源分析,痛点是数据量比较大,想要短时间能分析出来.再者就是之前在调查某酒店事件的时候特别羡慕某产商有各种分析溯源工具.反思过后,终于在没有那么忙的时候开始搭 ...
- 00常见的Linux系统版本
linux系统内核与linux发行套件系统并不相同: linux系统内核指的是一个由Linus Torvalds负责维护,提供硬件抽象层.硬盘及文件系统控制及多任务功能的系统核心程序. linux发行 ...
- RWD(Responsive Web Design)(转)
The key point is adapting to the user’s needs and device capabilities. Suppose a mobile user will be ...
- Python版本号比较函数 LooseVersion 和StrictVersion
- windows server没有这台电脑图标
rundll32.exe shell32.dll,Control_RunDLL desk.cpl,,0
- 498. Diagonal Traverse
题目思路 题目来源 C++实现 class Solution { public: vector<int> findDiagonalOrder(vector<vector<int ...
- javascript / angular 如何把object转成array
取出的api 格式是纯object格式 {"name":"james","city":"Taipei","co ...