当前位置:网站首页>Number of stair climbing methods of leetcode
Number of stair climbing methods of leetcode
2022-04-23 06:53:00 【zjLOVEcyj】
- climb stairs
Suppose you're climbing the stairs . need n You can reach the top of the building .
Every time you climb 1 or 2 A stair . How many different ways can you climb to the top of the building ?
Example 1:
Input :n = 2
Output :2
explain : There are two ways to climb to the top .
- 1 rank + 1 rank
- 2 rank
Example 2:
Input :n = 3
Output :3
explain : There are three ways to climb to the top .
- 1 rank + 1 rank + 1 rank
- 1 rank + 2 rank
- 2 rank + 1 rank
Tips :
1 <= n <= 45
var climbStairs = function(n) {
if (n === 1) return 1
if (n === 2) return 2
let n_1 = 2, n_2 = 1
let cur = 0
for (let i = 3; i <= n; i++) {
cur = n_1 + n_2
n_2 = n_1
n_1 = cur
}
return cur
}
res = climbStairs(3)
console.log(res);
版权声明
本文为[zjLOVEcyj]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/04/202204230555333429.html
边栏推荐
- Binary sum of leetcode questions
- 百度地图案例-修改地图样式
- el-cascader和el-select点击别处让下拉框消失
- Decentralized Collaborative Learning Framework for Next POI Recommendation
- SQL学习|窗口函数
- freeCodeCamp----budget & category 练习
- Unity3D对象池的理解与小例子
- Batch modify / batch update the value of a field in the database
- 柯里化实现函数连续调用计算累加和
- 1-3 NodeJS的安装之清单配置与跑项目环境
猜你喜欢
随机推荐
surprise库中evaluate函数弃用解决方法
1-2 NodeJS的特点
Get DOM element location information by offset and client
ES6规范详解
Scientists say Australian plan to cull up to 10,000 wild horses doesn’t go far enough
SignalR实现从服务端主动发送数据到客户端
offset和client获取dom元素位置信息
关于注解1
Leak detection and vacancy filling (V)
并发优化请求
.Net Core 下使用 Quartz —— 【2】作业和触发器之初步了解作业
EF CORE在ASP.NET CORE项目中基于数据库优先模式生成实体模型
ASP.NET CORE在类库项目中读取配置文件
JS handwriting compatibility event binding
file_get_contents 访问 ssl 错误的两种解决方法
js中entries(),keys(),values() , some(), Object.assign()遍历数组用法
Mailbox string judgment
Your brain expands and shrinks over time — these charts show how
Each traversal usage of tp6
修改Jupyter Notebook样式