Skip to content

Commit 2b9e7dd

Browse files
authored
Create Solution.ts
1 parent f82eaaa commit 2b9e7dd

File tree

1 file changed

+32
-0
lines changed

1 file changed

+32
-0
lines changed
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
class MyCalendarTwo {
2+
private events: [number, number][];
3+
private overlaps: [number, number][];
4+
5+
constructor() {
6+
this.events = [];
7+
this.overlaps = [];
8+
}
9+
10+
book(start: number, end: number): boolean {
11+
for (const [s, e] of this.overlaps) {
12+
if (Math.max(start, s) < Math.min(end, e)) {
13+
return false;
14+
}
15+
}
16+
17+
for (const [s, e] of this.events) {
18+
if (Math.max(start, s) < Math.min(end, e)) {
19+
this.overlaps.push([Math.max(start, s), Math.min(end, e)]);
20+
}
21+
}
22+
23+
this.events.push([start, end]);
24+
return true;
25+
}
26+
}
27+
28+
/**
29+
* Your MyCalendarTwo object will be instantiated and called as such:
30+
* var obj = new MyCalendarTwo()
31+
* var param_1 = obj.book(start,end)
32+
*/

0 commit comments

Comments
 (0)