Skip to content

Commit a7ad0cd

Browse files
committed
修改leetcode-master\problems\kamacoder\0044.开发商购买土地.md Java版本
1 parent e8a10ab commit a7ad0cd

File tree

1 file changed

+3
-2
lines changed

1 file changed

+3
-2
lines changed

problems/kamacoder/0044.开发商购买土地.md

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -212,13 +212,14 @@ public class Main {
212212
int horizontalCut = 0;
213213
for (int i = 0; i < n; i++) {
214214
horizontalCut += horizontal[i];
215-
result = Math.min(result, Math.abs(sum - 2 * horizontalCut));
215+
result = Math.min(result, Math.abs((sum - horizontalCut) - horizontalCut));
216+
// 更新result。其中,horizontalCut表示前i行的和,sum - horizontalCut表示剩下的和,作差、取绝对值,得到题目需要的“A和B各自的子区域内的土地总价值之差”。下同。
216217
}
217218

218219
int verticalCut = 0;
219220
for (int j = 0; j < m; j++) {
220221
verticalCut += vertical[j];
221-
result = Math.min(result, Math.abs(sum - 2 * verticalCut));
222+
result = Math.min(result, Math.abs((sum - verticalCut) - verticalCut));
222223
}
223224

224225
System.out.println(result);

0 commit comments

Comments
 (0)