当前位置:网站首页>leetcode70假设你正在爬楼梯。需要 n 阶你才能到达楼顶。每次你可以爬 1 或 2 个台阶。你有多少种不同的方法可以爬到楼顶呢?
leetcode70假设你正在爬楼梯。需要 n 阶你才能到达楼顶。每次你可以爬 1 或 2 个台阶。你有多少种不同的方法可以爬到楼顶呢?
2022-07-28 15:58:00 【从一而终】
class Solution {
public:
int climbStairs(int n) {
// 1 初始化数组
std::vector<int> f(n);
// 2 定义边界条件
if (n == 1)
{
return 1;
}
if (n == 2)
{
return 2;
}
f[0] = 1;
f[1] = 2;
// 3 状态转移方程
for (int i = 2; i < n; i++)
{
f[i] = f[i - 1] + f[i - 2];
}
// 4 找出结果
return f[n-1];
}
};边栏推荐
- Quickly master kotlin set functions
- 有趣的 Kotlin 0x07:Composition
- Asp.net large file block upload breakpoint resume demo
- Solve the width overflow of rich text pictures such as uniapp
- redis源码优化--绑核
- Several methods of HyperMesh running script files
- 微软100题-天天做-第16题
- LeetCode每日一练 —— 160. 相交链表
- 排序2-冒泡排序与快速排序(递归加非递归讲解)
- Splash (渲染JS服务)介绍安装
猜你喜欢

小程序:scroll-view默认滑倒最下面

ABAQUS GUI interface solves the problem of Chinese garbled code (plug-in Chinese garbled code is also applicable)

IM即时通讯开发优化提升连接成功率、速度等

USB产品(FX3、CCG3PA)的调试方法

LeetCode-学会对无序链表进行插入排序(详解)

Sort 1-insert sort and Hill sort

有趣的 Kotlin 0x07:Composition

ANSA二次开发 - Apps和ANSA插件管理

Configure HyperMesh secondary development environment on vs Code

【指针内功修炼】字符指针 + 指针数组 + 数组指针 + 指针参数(一)
随机推荐
PHP image upload
Interesting kotlin 0x07:composition
Early in the morning, pay Bora SMS to say that you won the "prize"? Dealing with server mining virus - kthreaddi
【JS】1394- ES2022 的 8 个实用的新功能
Signal shielding and processing
Oracle table partition
Ansa secondary development - build ansa secondary development environment on Visual Studio code
UNP前六章 回射服务模型 解析
Signal and slot mechanism of QT learning
MD5加密验证
Kubeedge releases white paper on cloud native edge computing threat model and security protection technology
Using pyqt to design gui in ABAQUS
Debugging methods of USB products (fx3, ccg3pa)
重置grafana登录密码为默认密码
Solve the width overflow of rich text pictures such as uniapp
Im im development optimization improves connection success rate, speed, etc
asp.net大文件分块上传断点续传demo
nowcode-学会删除链表中重复元素两题(详解)
How to set ticdc synchronization data to only synchronize the specified library?
Multiple commands produce '... /xxx.app/assets.car' problem