My Calendar II LeetCode solution in JavaScript

1
var MyCalendarTwo = function () {
2
this.calendar = [];
3
this.overlaps = [];
4
};
5

6
/**
7
* @param {number} start
8
* @param {number} end
9
* @return {boolean}
10
*/
11
MyCalendarTwo.prototype.book = function (start, end) {
12
for (let date of this.overlaps) {
13
if (start < date[1] && end > date[0]) return false;
14
}
15

16
for (let date of this.calendar) {
17
if (start < date[1] && end > date[0]) {
18
this.overlaps.push([Math.max(date[0], start), Math.min(date[1], end)]);
19
}
20
}
21
this.calendar.push([start, end]);
22
return true;
23
};

0

WPM •0 •0

100%

ACC •0 •0

0s

TIME •0