Skip to content

Commit 1eb8a18

Browse files
committed
Update index.ts
1 parent 1f6debc commit 1eb8a18

File tree

1 file changed

+9
-2
lines changed

1 file changed

+9
-2
lines changed

my-calendar-iii/index.ts

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ export default class MyCalendarThree {
1010
#search(start: number, end: number, node: SegmentTree): SegmentTree[] {
1111
start = Math.max(start, node.start);
1212
end = Math.min(end, node.end);
13+
// console.log(start, end, node);
1314
if (start > end || start > node.end || end < node.start) {
1415
return [];
1516
}
@@ -28,7 +29,7 @@ export default class MyCalendarThree {
2829
.map((v, i, a) => [v, a[i + 1] - 1])
2930
.slice(0, -1)
3031
.filter(([a, b]) => node.start <= a && node.end >= b);
31-
32+
/* children 按照从小到大排列 */
3233
node.children.push(
3334
...segments.map(([a, b]) => SegmentTree(a, b, node.value)),
3435
);
@@ -42,7 +43,13 @@ export default class MyCalendarThree {
4243
end: number,
4344
nodes: SegmentTree[],
4445
): SegmentTree[] {
45-
return nodes.map((child) => this.#search(start, end, child)).flat();
46+
// console.log([start, end, nodes]);
47+
// return nodes.map((child) => this.#search(start, end, child)).flat();
48+
const trees: SegmentTree[] = [];
49+
for (const child of nodes) {
50+
trees.push(...this.#search(start, end, child));
51+
}
52+
return trees;
4653
}
4754

4855
#increase(nodes: SegmentTree[]) {

0 commit comments

Comments
 (0)