leetcode: 70. Climbing Stairs
Problem
# 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.
AC
DP (动态规划):
class Solution():def climbStairs(self, n):pre, cur = 0, 1for _ in range(n):pre, cur = cur, pre + curreturn cur
递归,会 Time Limit Exceeded (超时):
# Time Limit Exceeded
class Solution():def climbStairs(self, n):if n == 1:return 1if n == 2:return 2return self.climbStairs(n - 1) + self.climbStairs(n - 2)if __name__ == "__main__":assert Solution().climbStairs(2) == 2
leetcode: 70. Climbing Stairs相关推荐
- 【斐波那切数列】LeetCode 70. Climbing Stairs
LeetCode 70. Climbing Stairs 这是一道利用斐波那切数列求解的题目.求斐波那切数列有比较经典的4种方法 (1)递归法:复杂度太高 (2)迭代法:时间复杂度为O(n)O(n)O ...
- [勇者闯LeetCode] 70. Climbing Stairs
[勇者闯LeetCode] 70. Climbing Stairs Description You are climbing a stair case. It takes n steps to rea ...
- [LeetCode]70.Climbing Stairs
[题目] You are climbing a stair case. It takes n steps to reach to the top. Each time you can either c ...
- [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#70 Climbing Stairs
Problem Definition: You are climbing a stair case. It takes n steps to reach to the top. Each time y ...
- 70. Climbing Stairs
70. Climbing Stairs 1. 题目 You are climbing a stair case. It takes n steps to reach to the top. Each ...
- leetcode python3 简单题70. Climbing Stairs
1.编辑器 我使用的是win10+vscode+leetcode+python3 环境配置参见我的博客: 链接 2.第七十题 (1)题目 英文: You are climbing a stair ca ...
- 【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 ...
最新文章
- 易语言读写配置项ini文件
- proxy error: could not proxy request解决方案
- 背景图片生成网站收集
- 【nginx】【小记】泛解析大量域名的情况下 将不带www的域名,301到与之对应的www前缀的域名
- favicon.ico是什么?
- java concurrent 框架_Java Concurrent 框架图
- Criteo公司在上海新开通一个数据中心
- 浏览器对象模型(Browser Object Model)
- SVN配置–服务器端(linux)
- MultiDesk远程桌面连接
- 项目管理之敏捷开发之道
- uniapp实现公众号H5、小程序和App微信授权登录功能
- 入选数据库顶会 VLDB:如何有效降低产品级内存数据库快照尾延迟?
- linux中用zip压缩文件,详解Linux中zip压缩和unzip解压缩命令及使用详解
- 用Python编写的五子棋程序1.0版
- 史上最完美的 Typora 教程
- 动态规划--数位dp--二进制状态压缩
- 注意力机制工作原理详解
- 是否能构成三角形java
- 笔记本开机后桌面图标变乱