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 32185d5

Browse files
編輯JAVA解答的部分內容
1. 提供JAVA填充數組的函數Arrays.fill() 2. for loop中不需要if statement,並有用 // 解釋原因
1 parent 6156804 commit 32185d5

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

‎problems/0279.完全平方数.md‎

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -177,15 +177,19 @@ class Solution {
177177
for (int j = 0; j <= n; j++) {
178178
dp[j] = max;
179179
}
180+
//如果不想要寫for-loop填充數組的話,也可以用JAVA內建的Arrays.fill()函數。
181+
//Arrays.fill(dp, Integer.MAX_VALUE);
182+
180183
//当和为0时,组合的个数为0
181184
dp[0] = 0;
182185
// 遍历物品
183186
for (int i = 1; i * i <= n; i++) {
184187
// 遍历背包
185188
for (int j = i * i; j <= n; j++) {
186-
if (dp[j - i * i] != max) {
189+
//if (dp[j - i * i] != max) {
187190
dp[j] = Math.min(dp[j], dp[j - i * i] + 1);
188-
}
191+
//}
192+
//不需要這個if statement,因爲在完全平方數這一題不會有"湊不成"的狀況發生( 一定可以用"1"來組成任何一個n),故comment掉這個if statement。
189193
}
190194
}
191195
return dp[n];

0 commit comments

Comments
(0)

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