Skip to content

Commit f5ef073

Browse files
authored
Create Solution.js
1 parent 4316b1e commit f5ef073

File tree

1 file changed

+33
-0
lines changed

1 file changed

+33
-0
lines changed
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
2+
var MyCalendarTwo = function() {
3+
this.events = [];
4+
this.overlaps = [];
5+
};
6+
7+
/**
8+
* @param {number} start
9+
* @param {number} end
10+
* @return {boolean}
11+
*/
12+
MyCalendarTwo.prototype.book = function(start, end) {
13+
for (let [s, e] of this.overlaps) {
14+
if (Math.max(start, s) < Math.min(end, e)) {
15+
return false;
16+
}
17+
}
18+
19+
for (let [s, e] of this.events) {
20+
if (Math.max(start, s) < Math.min(end, e)) {
21+
this.overlaps.push([Math.max(start, s), Math.min(end, e)]);
22+
}
23+
}
24+
25+
this.events.push([start, end]);
26+
return true;
27+
};
28+
29+
/**
30+
* Your MyCalendarTwo object will be instantiated and called as such:
31+
* var obj = new MyCalendarTwo()
32+
* var param_1 = obj.book(start,end)
33+
*/

0 commit comments

Comments
 (0)