Skip to content

Commit

Permalink
Merge pull request youngyangyang04#2119 from Lozakaka/patch-17
Browse files Browse the repository at this point in the history
編輯JAVA解答的部分內容
  • Loading branch information
youngyangyang04 authored Jun 17, 2023
2 parents 49d94a3 + 32185d5 commit 59a9280
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions problems/0279.完全平方数.md
Original file line number Diff line number Diff line change
Expand Up @@ -177,15 +177,19 @@ class Solution {
for (int j = 0; j <= n; j++) {
dp[j] = max;
}
//如果不想要寫for-loop填充數組的話,也可以用JAVA內建的Arrays.fill()函數。
//Arrays.fill(dp, Integer.MAX_VALUE);
//当和为0时,组合的个数为0
dp[0] = 0;
// 遍历物品
for (int i = 1; i * i <= n; i++) {
// 遍历背包
for (int j = i * i; j <= n; j++) {
if (dp[j - i * i] != max) {
//if (dp[j - i * i] != max) {
dp[j] = Math.min(dp[j], dp[j - i * i] + 1);
}
//}
//不需要這個if statement,因爲在完全平方數這一題不會有"湊不成"的狀況發生( 一定可以用"1"來組成任何一個n),故comment掉這個if statement。
}
}
return dp[n];
Expand Down

0 comments on commit 59a9280

Please sign in to comment.