File tree Expand file tree Collapse file tree 1 file changed +33
-0
lines changed
solution/0700-0799/0731.My Calendar II Expand file tree Collapse file tree 1 file changed +33
-0
lines changed Original file line number Diff line number Diff line change
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
+ */
You can’t perform that action at this time.
0 commit comments