File tree Expand file tree Collapse file tree 1 file changed +32
-0
lines changed
solution/0700-0799/0731.My Calendar II Expand file tree Collapse file tree 1 file changed +32
-0
lines changed Original file line number Diff line number Diff line change
1
+ class MyCalendarTwo {
2
+ private events : [ number , number ] [ ] ;
3
+ private overlaps : [ number , number ] [ ] ;
4
+
5
+ constructor ( ) {
6
+ this . events = [ ] ;
7
+ this . overlaps = [ ] ;
8
+ }
9
+
10
+ book ( start : number , end : number ) : boolean {
11
+ for ( const [ s , e ] of this . overlaps ) {
12
+ if ( Math . max ( start , s ) < Math . min ( end , e ) ) {
13
+ return false ;
14
+ }
15
+ }
16
+
17
+ for ( const [ s , e ] of this . events ) {
18
+ if ( Math . max ( start , s ) < Math . min ( end , e ) ) {
19
+ this . overlaps . push ( [ Math . max ( start , s ) , Math . min ( end , e ) ] ) ;
20
+ }
21
+ }
22
+
23
+ this . events . push ( [ start , end ] ) ;
24
+ return true ;
25
+ }
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