当前位置:网站首页>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
边栏推荐
猜你喜欢
随机推荐
window环境下使用小皮面板安装redis
JS正则匹配先行断言和后行断言
Batch modify / batch update the value of a field in the database
New type of dark energy could solve Universe expansion mystery
Scientists say Australian plan to cull up to 10,000 wild horses doesn’t go far enough
NodeJS 模块之间的使用
ASP.NET CORE3.1 Identity注册用户后登录失败的解决方案
1-5 NodeJS CommonJs规范
Add serial number to El table
关于注解1
sql中的 IF 条件语句的用法
New formdata() when importing files
最近编程中遇到的一些问题2021/9/8
阅读笔记:Secure Federated Matrix Factorization
Get DOM element location information by offset and client
Set and map
file_ get_ Two solutions to content accessing SSL errors
七牛上传图片(前台JS+后台C#API获取token)
DNA reveals surprise ancestry of mysterious Chinese mummies
input文件上传