当前位置:网站首页>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];
}
}
边栏推荐
- Introduction to armv8/armv9 - learning this article is enough
- [learning notes] xr872 GUI littlevgl 8.0 migration (file system)
- Leetcode 473. Match to square [violence + pruning]
- Opencv 10 brightness contrast adjustment
- C # illustrated tutorial (Fourth Edition) chapter7-7.2 accessing inherited members
- About the fact that I gave up the course of "Guyue private room course ROS manipulator development from introduction to actual combat" halfway
- js-dom
- [pytorch]fixmatch code explanation - data loading
- json,xml,txt
- Exam23 named windows and simplified paths, grayscale conversion
猜你喜欢
05 tabbar navigation bar function
[pytorch]fixmatch code explanation (super detailed)
Think about the possibility of attacking secure memory through mmu/tlb/cache
Fast Color Segementation
Superficial understanding of conditional random fields
哈夫曼树及其应用
[reading papers] deep learning face representation by joint identification verification, deep learning applied to optimization problems, deepid2
1、 Set up Django automation platform (realize one click SQL execution)
Barrykay electronics rushes to the scientific innovation board: it is planned to raise 360million yuan. Mr. and Mrs. Wang Binhua are the major shareholders
How to destroy a fragment- How to destroy Fragment?
随机推荐
[reading point paper] deeplobv3+ encoder decoder with Atlas separable revolution
[pytorch]fixmatch code explanation (super detailed)
Matlab: obtain the figure edge contour and divide the figure n equally
[keras learning]fit_ Generator analysis and complete examples
Common web page status return code crawler
Exam23 named windows and simplified paths, grayscale conversion
How to do Internet for small enterprises
Basic principle of bilateral filtering
Chapter7-10_ Deep Learning for Question Answering (1/2)
Understand HMM
05 tabbar navigation bar function
Huffman tree and its application
Impossible d'afficher le contenu de la base de données après que l'idée a utilisé le pool de connexion c3p0 pour se connecter à la base de données SQL
[reading point paper] yolo9000:better, faster, stronger, (yolov2), integrating various methods to improve the idea of map and wordtree data fusion
L1 regularization and its sparsity
Basic exercise of test questions decimal to hexadecimal
Share three stories about CMDB
[reading papers] dcgan, the combination of generating countermeasure network and deep convolution
Introduction to armv8/armv9 - learning this article is enough
The fastest empty string comparison method C code