mirror of
https://github.com/youngyangyang04/leetcode-master.git
synced 2025-07-07 15:45:40 +08:00
@ -128,12 +128,12 @@ Java:
|
|||||||
class Solution {
|
class Solution {
|
||||||
public int climbStairs(int n) {
|
public int climbStairs(int n) {
|
||||||
int[] dp = new int[n + 1];
|
int[] dp = new int[n + 1];
|
||||||
int[] weight = {1,2};
|
int m = 2;
|
||||||
dp[0] = 1;
|
dp[0] = 1;
|
||||||
|
|
||||||
for (int i = 0; i <= n; i++) {
|
for (int i = 1; i <= n; i++) { // 遍历背包
|
||||||
for (int j = 0; j < weight.length; j++) {
|
for (int j = 1; j <= m; j++) { //遍历物品
|
||||||
if (i >= weight[j]) dp[i] += dp[i - weight[j]];
|
if (i >= j) dp[i] += dp[i - j];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -227,3 +227,4 @@ function climbStairs(n: number): number {
|
|||||||
<a href="https://programmercarl.com/other/kstar.html" target="_blank">
|
<a href="https://programmercarl.com/other/kstar.html" target="_blank">
|
||||||
<img src="../pics/网站星球宣传海报.jpg" width="1000"/>
|
<img src="../pics/网站星球宣传海报.jpg" width="1000"/>
|
||||||
</a>
|
</a>
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user