当前位置:网站首页>Advanced stair climbing
Advanced stair climbing
2022-06-13 02:33:00 【Prodigal son's private dishes】
subject :
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 ?
Be careful : Given n Is a positive integer .
Example 1: Input : 2 Output : 2 explain : There are two ways to climb to the top .
1 rank + 1 rank
2 rank
Example 2: Input : 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
Code :
class Solution {
public int climbStairs(int n) {
int[] dp = new int[n+1];
int[] weight = {1, 2};
dp[0] = 1;
for(int i = 0; i <= n; i++){
for(int j = 0; j < weight.length; j++){
if(i >= weight[j]){
dp[i] += dp[i-weight[j]];
}
}
}
return dp[n];
}
}
边栏推荐
- OpenCVSharpSample04WinForms
- Sans certificate generation
- Introduction to easydl object detection port
- Image table solid line and dashed line detection
- ROS learning -5 how function packs with the same name work (workspace coverage)
- OpenCVSharpSample05Wpf
- Opencv 9 resize size change rotate rotate blur mean (blur)
- [pytorch]fixmatch code explanation - data loading
- Opencv 10 brightness contrast adjustment
- Basic exercise of test questions decimal to hexadecimal
猜你喜欢

Understand speech denoising

Classification and summary of system registers in aarch64 architecture of armv8/arnv9

How to destroy a fragment- How to destroy Fragment?
![Leetcode 473. 火柴拼正方形 [暴力+剪枝]](/img/3a/975b91dd785e341c561804175b6439.png)
Leetcode 473. 火柴拼正方形 [暴力+剪枝]

Opencvshare4 and vs2019 configuration
![Leetcode 450. Delete node in binary search tree [binary search tree]](/img/39/d5c4d424a160635791c4645d6f2e10.png)
Leetcode 450. Delete node in binary search tree [binary search tree]

ROS learning-7 error in custom message or service reference header file
![[pytorch]fixmatch code explanation (super detailed)](/img/22/66703bea0f8ee40eceb0687fcb3ad2.jpg)
[pytorch]fixmatch code explanation (super detailed)

Paper reading - jukebox: a generic model for music

Understand CRF
随机推荐
Common web page status return code crawler
Leetcode 473. 火柴拼正方形 [暴力+剪枝]
Leetcode 450. 删除二叉搜索树中的节点 [二叉搜索树]
[pytorch] kaggle image classification competition arcface + bounding box code learning
[analysis notes] source code analysis of siliconlabs efr32bg22 Bluetooth mesh sensorclient
Bai ruikai Electronic sprint Scientific Innovation Board: proposed to raise 360 million Funds, Mr. And Mrs. Wang binhua as the main Shareholder
Chapter7-13_ Dialogue State Tracking (as Question Answering)
Basic exercises of test questions Fibonacci series
1、 Set up Django automation platform (realize one click SQL execution)
Understand speech denoising
Introduction to easydl object detection port
哈夫曼树及其应用
[reading point paper] yolo9000:better, faster, stronger, (yolov2), integrating various methods to improve the idea of map and wordtree data fusion
too old resource version,Code:410
在IDEA使用C3P0连接池连接SQL数据库后却不能显示数据库内容
How to learn to understand Matplotlib instead of simple code reuse
Restrict cell input type and display format in CXGRID control
js-dom
Mean Value Coordinates
03 认识第一个view组件