Skip to content

Commit 4fa8d69

Browse files
committed
Update index.ts
1 parent aec23f6 commit 4fa8d69

File tree

1 file changed

+4
-14
lines changed

1 file changed

+4
-14
lines changed

rectangle-area-ii/index.ts

Lines changed: 4 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -6,18 +6,15 @@ function rectangleArea(rectangles: number[][]): number {
66

77
const total = { left, right, down, up };
88
const root = new SegmentNode(total);
9-
// console.log(root, total);
9+
1010
for (const [left, down, right, up] of rectangles) {
11-
change(root, /* total, */ { left, right, down, up }, 1n);
12-
// console.log(root, total);
11+
change(root, { left, right, down, up }, 1n);
1312
}
1413

15-
// console.log(root)
1614
return Number(root.value % BigInt(10 ** 9 + 7));
1715
}
1816
function change(
1917
node: SegmentNode,
20-
// current: Interval,
2118
target: Interval,
2219
value: bigint,
2320
) {
@@ -30,15 +27,13 @@ function change(
3027
) {
3128
return;
3229
}
33-
// console.log({ node, current, target, value });
3430

3531
if (
3632
target.left <= current.left &&
3733
target.down <= current.down &&
3834
target.right >= current.right &&
3935
target.up >= current.up
4036
) {
41-
// console.log("找到了包含target的范围了");
4237
if (node.children.length === 0) {
4338
node.value = value *
4439
BigInt(current.right - current.left) *
@@ -54,7 +49,7 @@ function change(
5449
current.down < a && current.up > a
5550
)[0] ?? current.up;
5651
const subinterval = TwoDSplit(current, midx, midy);
57-
// console.log(current, subinterval);
52+
5853
if (subinterval.length) {
5954
node.children = subinterval.map(
6055
(c) =>
@@ -66,18 +61,13 @@ function change(
6661
),
6762
);
6863
}
69-
// console.log("创建子节点", node.value, node.children);
7064
}
7165
}
7266
if (node.children.length) {
73-
// for (const [index, next] of subinterval.entries()) {
74-
// change(node.children[index], /* next, */ target, value);
75-
// }
76-
7767
for (const child of node.children) {
7868
change(child, target, value);
7969
}
80-
//可能没有子节点
70+
8171
node.value = node.children.length
8272
? node.children.reduce((a, n) => a + n.value, 0n)
8373
: node.value;

0 commit comments

Comments
 (0)