当前位置:网站首页>Leetcode70 suppose you are climbing stairs. You need n steps to reach the roof. You can climb one or two steps at a time. How many different ways can you climb to the roof?
Leetcode70 suppose you are climbing stairs. You need n steps to reach the roof. You can climb one or two steps at a time. How many different ways can you climb to the roof?
2022-07-28 16:53:00 【be faithful to one 's husband unto death】
class Solution {
public:
int climbStairs(int n) {
// 1 Initialize array
std::vector<int> f(n);
// 2 Define boundary conditions
if (n == 1)
{
return 1;
}
if (n == 2)
{
return 2;
}
f[0] = 1;
f[1] = 2;
// 3 State transition equation
for (int i = 2; i < n; i++)
{
f[i] = f[i - 1] + f[i - 2];
}
// 4 Find out the results
return f[n-1];
}
};边栏推荐
- The local area network cannot access the Apache server
- 结构化设计的概要与原理--模块化
- 【JS】1394- ES2022 的 8 个实用的新功能
- 给定正整数N、M,均介于1~10 ^ 9之间,N <= M,找出两者之间(含N、M)的位数为偶数的数有多少个
- Microsoft question 100 - do it every day - question 11
- “蔚来杯“2022牛客暑期多校训练营3 J.Journey 0-1最短路
- Call DLL file without source code
- 有趣的 Kotlin 0x0A:Fun with composition
- [JS] eight practical new functions of 1394-es2022
- [learn slam from scratch] publish the coordinate system transformation relationship to topic TF
猜你喜欢

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

遭MQ连连干翻后的醒悟!含恨码出这份MQ手册助力秋招之旅

Fx3 development board and schematic diagram

Early in the morning, pay Bora SMS to say that you won the "prize"? Dealing with server mining virus - kthreaddi

IM即时通讯软件开发网络请求成功率的优化

ANSYS secondary development - MFC interface calls ADPL file

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

Interesting kotlin 0x07:composition

Use js direct OSS to store files in Alibaba cloud and solve the limitation of large file upload server

Configure HyperMesh secondary development environment on vs Code
随机推荐
Kubeedge releases white paper on cloud native edge computing threat model and security protection technology
"Wei Lai Cup" 2022 Niuke summer multi school training camp 3 j.journey 0-1 shortest path
ABAQUS GUI interface solves the problem of Chinese garbled code (plug-in Chinese garbled code is also applicable)
asmlinkage的理解
Cluster construction and use of redis5
“蔚来杯“2022牛客暑期多校训练营3 A.Ancestor LCA+暴力计数
MySQL5.7及SQLyogV12安装及使用破解及常用命令
PHP calculate coordinate distance
有趣的 Kotlin 0x07:Composition
Signal and slot mechanism of QT learning
“蔚来杯“2022牛客暑期多校训练营3 J.Journey 0-1最短路
有趣的 Kotlin 0x0A:Fun with composition
Leetcode learn to insert and sort unordered linked lists (detailed explanation)
Ansa secondary development - apps and ansa plug-in management
[learn slam from scratch] publish the coordinate system transformation relationship to topic TF
Several methods of HyperMesh running script files
ANSYS secondary development - MFC interface calls ADPL file
Oracle system composition
Best cow fences solution
epoll水平出发何边沿触发