Skip to content

Commit aec23f6

Browse files
committed
Update index.ts
1 parent 700c559 commit aec23f6

File tree

1 file changed

+6
-3
lines changed

1 file changed

+6
-3
lines changed

rectangle-area-ii/index.ts

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -49,11 +49,12 @@ function change(
4949
if (node.children.length === 0) {
5050
const midx = [target.left, target.right].filter((a) =>
5151
current.left < a && current.right > a
52-
)[0];
52+
)[0] ?? current.right;
5353
const midy = [target.down, target.up].filter((a) =>
5454
current.down < a && current.up > a
55-
)[0];
55+
)[0] ?? current.up;
5656
const subinterval = TwoDSplit(current, midx, midy);
57+
// console.log(current, subinterval);
5758
if (subinterval.length) {
5859
node.children = subinterval.map(
5960
(c) =>
@@ -112,7 +113,9 @@ export function TwoDSplit(
112113
.flat();
113114
return result.filter(
114115
({ left, right, up, down }) =>
115-
left <= right && down <= up && (right - left) * (up - down),
116+
left <= right && down <= up && (right - left) * (up - down) &&
117+
!(left === current.left && down === current.down &&
118+
up === current.up && right === current.right),
116119
);
117120
}
118121
export class SegmentNode {

0 commit comments

Comments
 (0)