Skip to content

Commit 675f0be

Browse files
authored
Update README.md
1 parent 1b043e0 commit 675f0be

File tree

1 file changed

+37
-0
lines changed
  • solution/0700-0799/0731.My Calendar II

1 file changed

+37
-0
lines changed

solution/0700-0799/0731.My Calendar II/README.md

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -208,6 +208,43 @@ func (this *MyCalendarTwo) Book(start int, end int) bool {
208208
*/
209209
```
210210

211+
#### TypeScript
212+
213+
```ts
214+
class MyCalendarTwo {
215+
private events: [number, number][];
216+
private overlaps: [number, number][];
217+
218+
constructor() {
219+
this.events = [];
220+
this.overlaps = [];
221+
}
222+
223+
book(start: number, end: number): boolean {
224+
for (const [s, e] of this.overlaps) {
225+
if (Math.max(start, s) < Math.min(end, e)) {
226+
return false;
227+
}
228+
}
229+
230+
for (const [s, e] of this.events) {
231+
if (Math.max(start, s) < Math.min(end, e)) {
232+
this.overlaps.push([Math.max(start, s), Math.min(end, e)]);
233+
}
234+
}
235+
236+
this.events.push([start, end]);
237+
return true;
238+
}
239+
}
240+
241+
/**
242+
* Your MyCalendarTwo object will be instantiated and called as such:
243+
* var obj = new MyCalendarTwo()
244+
* var param_1 = obj.book(start,end)
245+
*/
246+
```
247+
211248
#### JavaScript
212249

213250
```js

0 commit comments

Comments
 (0)