731.js
/** ------------------------------------------------------------------------------
*
* 731. My Calendar II
* Topics: 토픽
* https://leetcode.com/problems/my-calendar-ii/description/?envType=daily-question&envId=2024-09-27
*
------------------------------------------------------------------------------ */
var MyCalendarTwo = function () {
this.cal = []
this.overlaps = []
}
/**
* @param {number} start
* @param {number} end
* @return {boolean}
*/
MyCalendarTwo.prototype.book = function (start, end) {
console.log("cal: ", this.cal)
console.log("overlaps: ", this.overlaps)
for (let [s, e] of this.overlaps) {
if (start < e && end > s) return false
}
for (let [s, e] of this.cal) {
if (start < e && end > s) {
this.overlaps.push([Math.max(start, s), Math.min(end, e)])
}
}
this.cal.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)
*/