Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 37 additions & 0 deletions solution/0700-0799/0731.My Calendar II/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -208,6 +208,43 @@ func (this *MyCalendarTwo) Book(start int, end int) bool {
*/
```

#### TypeScript

```ts
class MyCalendarTwo {
private events: [number, number][];
private overlaps: [number, number][];

constructor() {
this.events = [];
this.overlaps = [];
}

book(start: number, end: number): boolean {
for (const [s, e] of this.overlaps) {
if (Math.max(start, s) < Math.min(end, e)) {
return false;
}
}

for (const [s, e] of this.events) {
if (Math.max(start, s) < Math.min(end, e)) {
this.overlaps.push([Math.max(start, s), Math.min(end, e)]);
}
}

this.events.push([start, end]);
return true;
}
}

/**
* Your MyCalendarTwo object will be instantiated and called as such:
* var obj = new MyCalendarTwo()
* var param_1 = obj.book(start,end)
*/
```

#### JavaScript

```js
Expand Down
37 changes: 37 additions & 0 deletions solution/0700-0799/0731.My Calendar II/README_EN.md
Original file line number Diff line number Diff line change
Expand Up @@ -206,6 +206,43 @@ func (this *MyCalendarTwo) Book(start int, end int) bool {
*/
```

#### TypeScript

```ts
class MyCalendarTwo {
private events: [number, number][];
private overlaps: [number, number][];

constructor() {
this.events = [];
this.overlaps = [];
}

book(start: number, end: number): boolean {
for (const [s, e] of this.overlaps) {
if (Math.max(start, s) < Math.min(end, e)) {
return false;
}
}

for (const [s, e] of this.events) {
if (Math.max(start, s) < Math.min(end, e)) {
this.overlaps.push([Math.max(start, s), Math.min(end, e)]);
}
}

this.events.push([start, end]);
return true;
}
}

/**
* Your MyCalendarTwo object will be instantiated and called as such:
* var obj = new MyCalendarTwo()
* var param_1 = obj.book(start,end)
*/
```

#### JavaScript

```js
Expand Down
32 changes: 32 additions & 0 deletions solution/0700-0799/0731.My Calendar II/Solution.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
class MyCalendarTwo {
private events: [number, number][];
private overlaps: [number, number][];

constructor() {
this.events = [];
this.overlaps = [];
}

book(start: number, end: number): boolean {
for (const [s, e] of this.overlaps) {
if (Math.max(start, s) < Math.min(end, e)) {
return false;
}
}

for (const [s, e] of this.events) {
if (Math.max(start, s) < Math.min(end, e)) {
this.overlaps.push([Math.max(start, s), Math.min(end, e)]);
}
}

this.events.push([start, end]);
return true;
}
}

/**
* Your MyCalendarTwo object will be instantiated and called as such:
* var obj = new MyCalendarTwo()
* var param_1 = obj.book(start,end)
*/
Loading