File tree Expand file tree Collapse file tree 1 file changed +32
-0
lines changed Expand file tree Collapse file tree 1 file changed +32
-0
lines changed Original file line number Diff line number Diff line change
1
+ const 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 i = 0 ; i < this . overlaps . length ; i ++ ) {
13
+ if ( start < this . overlaps [ i ] . end && end > this . overlaps [ i ] . start )
14
+ return false
15
+ }
16
+
17
+ for ( let i = 0 ; i < this . calendar . length ; i ++ ) {
18
+ if ( start < this . calendar [ i ] . end && end > this . calendar [ i ] . start )
19
+ this . overlaps . push ( {
20
+ start : Math . max ( start , this . calendar [ i ] . start ) ,
21
+ end : Math . min ( end , this . calendar [ i ] . end ) ,
22
+ } )
23
+ }
24
+ this . calendar . push ( { start : start , end : end } )
25
+ return true
26
+ }
27
+
28
+ /**
29
+ * Your MyCalendarTwo object will be instantiated and called as such:
30
+ * var obj = new MyCalendarTwo()
31
+ * var param_1 = obj.book(start,end)
32
+ */
You can’t perform that action at this time.
0 commit comments