当前位置:网站首页>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];
}
};边栏推荐
- MySQL CDC if the binlog log file is incomplete, can you read all the data in the full volume stage
- 学会使用MySQL的Explain执行计划,SQL性能调优从此不再困难
- Splash (渲染JS服务)介绍安装
- 每一个账号对应所有密码,再每一个密码对应所有账号暴力破解代码怎么写?...
- Leetcode learn complex questions with random pointer linked lists (detailed explanation)
- 小程序:scroll-view默认滑倒最下面
- Splash (rendering JS service) introduction installation
- egg(十九):使用egg-redis性能优化,缓存数据提升响应效率
- Installation of QT learning
- redis源码优化--绑核
猜你喜欢

阿里大哥教你如何正确认识关于标准IO缓冲区的问题

Interesting kotlin 0x09:extensions are resolved statically

Call DLL file without source code

HyperMesh auto save (enhanced) plug-in instructions

Fx3 development board and schematic diagram

HyperMesh运行脚本文件的几种方法

排序2-冒泡排序与快速排序(递归加非递归讲解)

QT packaging

Introduction and implementation of stack (detailed explanation)

Configure HyperMesh secondary development environment on vs Code
随机推荐
Microsoft question 100 - do it every day - question 11
Qt学习之Qt Designer(设计师)
Installation of QT learning
redis源码优化--绑核
微软:Edge 浏览器已内置磁盘缓存压缩技术,可节省空间占用且不降低系统性能
一小时内学会Abaqus脚本编程秘籍
Sort 5-count sort
IM即时通讯软件开发网络请求成功率的优化
ANSA二次开发 - Apps和ANSA插件管理
"Wei Lai Cup" 2022 Niuke summer multi school training camp 3 a.ancestor lca+ violence count
HM二次开发 - Data Names及其使用
有趣的 Kotlin 0x08:What am I
“蔚来杯“2022牛客暑期多校训练营3 A.Ancestor LCA+暴力计数
阿里大哥教你如何正确认识关于标准IO缓冲区的问题
2021-04-02
Several methods of HyperMesh running script files
Splash (渲染JS服务)介绍安装
栈的介绍与实现(详解)
Qt学习之安装
Fx3 development board and schematic diagram