当前位置:网站首页>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];
}
};边栏推荐
- Interesting kotlin 0x09:extensions are resolved statically
- 信号屏蔽与处理
- ANSYS secondary development - MFC interface calls ADPL file
- Best Cow Fences 题解
- LwIP development | socket | UDP
- Some suggestions on optimizing HyperMesh script performance
- Redis source code optimization -- binding core
- Debugging methods of USB products (fx3, ccg3pa)
- Ruoyi集成flyway后启动报错的解决方法
- Microsoft question 100 - do it every day - question 11
猜你喜欢

Ansa secondary development - Introduction to interface development tools

Text filtering skills

Kubeedge releases white paper on cloud native edge computing threat model and security protection technology

Sort 1-insert sort and Hill sort

有趣的 Kotlin 0x09:Extensions are resolved statically

Configure HyperMesh secondary development environment on vs Code

队列的介绍与实现(详解)

Leetcode learn complex questions with random pointer linked lists (detailed explanation)

HyperMesh auto save (enhanced) plug-in instructions

Optimization of network request success rate in IM instant messaging software development
随机推荐
FX3开发板 及 原理图
Sort 4-heap sort and massive TOPK problem
"Wei Lai Cup" 2022 Niuke summer multi school training camp 3 a.ancestor lca+ violence count
“蔚来杯“2022牛客暑期多校训练营3 ACFHJ
【指针内功修炼】字符指针 + 指针数组 + 数组指针 + 指针参数(一)
获取时间戳的三种方法的效率比较
Ruoyi集成flyway后启动报错的解决方法
Debugging methods of USB products (fx3, ccg3pa)
Some suggestions on optimizing HyperMesh script performance
nowcode-学会删除链表中重复元素两题(详解)
Wake up after being repeatedly upset by MQ! Hate code out this MQ manual to help the journey of autumn recruitment
Applet: get element node information
Best cow fences solution
结构化设计的概要与原理--模块化
Design direction of daily development plan
有趣的 Kotlin 0x06:List minus list
egg(十九):使用egg-redis性能优化,缓存数据提升响应效率
关于MIT6.828_HW9_barriers xv6 homework9的一些问题
TCP handshake, waving, time wait connection reset and other records
关于Bug处理的一些看法