Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 17a01ce

Browse files
新增java註解
新增java註解 if statement的解釋
1 parent accc97c commit 17a01ce

File tree

1 file changed

+3
-2
lines changed

1 file changed

+3
-2
lines changed

‎problems/0070.爬楼梯完全背包版本.md‎

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -133,12 +133,13 @@ Java:
133133
class Solution {
134134
public int climbStairs(int n) {
135135
int[] dp = new int[n + 1];
136-
int m = 2;
136+
int m = 2; //有兩個物品:itme1重量爲一,item2重量爲二
137137
dp[0] = 1;
138138
139139
for (int i = 1; i <= n; i++) { // 遍历背包
140140
for (int j = 1; j <= m; j++) { //遍历物品
141-
if (i >= j) dp[i] += dp[i - j];
141+
if (i >= j) //當前的背包容量 大於 物品重量的時候,我們才需要記錄當前的這個裝得方法(方法數+)
142+
dp[i] += dp[i - j];
142143
}
143144
}
144145

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /