-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path731.js
More file actions
26 lines (25 loc) · 693 Bytes
/
731.js
File metadata and controls
26 lines (25 loc) · 693 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
var MyCalendarTwo = function() {
this.records = [];
this.overlaps = [];
};
/**
* @param {number} start
* @param {number} end
* @return {boolean}
*/
MyCalendarTwo.prototype.book = function(start, end) {
for(let i=0;i<this.overlaps.length;i++){
let l = Math.max(start,this.overlaps[i][0]), r = Math.min(end,this.overlaps[i][1]);
if(l<r){//overlap
return false;
}
}
for(let i=0;i<this.records.length;i++){
let l = Math.max(start,this.records[i][0]), r = Math.min(end,this.records[i][1]);
if(l<r){//overlap
this.overlaps.push([l,r]);
}
}
this.records.push([start,end]);
return true;
};