We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent e8a10ab commit a7ad0cdCopy full SHA for a7ad0cd
problems/kamacoder/0044.开发商购买土地.md
@@ -212,13 +212,14 @@ public class Main {
212
int horizontalCut = 0;
213
for (int i = 0; i < n; i++) {
214
horizontalCut += horizontal[i];
215
- result = Math.min(result, Math.abs(sum - 2 * horizontalCut));
+ result = Math.min(result, Math.abs((sum - horizontalCut) - horizontalCut));
216
+ // 更新result。其中,horizontalCut表示前i行的和,sum - horizontalCut表示剩下的和,作差、取绝对值,得到题目需要的“A和B各自的子区域内的土地总价值之差”。下同。
217
}
218
219
int verticalCut = 0;
220
for (int j = 0; j < m; j++) {
221
verticalCut += vertical[j];
- result = Math.min(result, Math.abs(sum - 2 * verticalCut));
222
+ result = Math.min(result, Math.abs((sum - verticalCut) - verticalCut));
223
224
225
System.out.println(result);
0 commit comments