Skip to content

Commit

Permalink
feat: add ts solution to lc problem: No.0731 (#3573)
Browse files Browse the repository at this point in the history
  • Loading branch information
07subhadip authored Sep 27, 2024
1 parent 1dedc2b commit 15492af
Show file tree
Hide file tree
Showing 3 changed files with 106 additions and 0 deletions.
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)
*/

0 comments on commit 15492af

Please sign in to comment.