File tree Expand file tree Collapse file tree 1 file changed +43
-0
lines changed Expand file tree Collapse file tree 1 file changed +43
-0
lines changed Original file line number Diff line number Diff line change
1
+ const find = ( cals , time , count ) => {
2
+ let l = 0
3
+ let r = cals . length
4
+ let mid
5
+ while ( l < r ) {
6
+ mid = Math . trunc ( ( l + r ) / 2 )
7
+ if ( cals [ mid ] [ 0 ] === time ) {
8
+ cals [ mid ] [ 1 ] += count
9
+ return
10
+ } else if ( cals [ mid ] [ 0 ] < time ) {
11
+ l = mid + 1
12
+ } else {
13
+ r = mid
14
+ }
15
+ }
16
+ cals . splice ( l , 0 , [ time , count ] )
17
+ }
18
+ const MyCalendarThree = function ( ) {
19
+ this . cals = [ ]
20
+ }
21
+
22
+ /**
23
+ * @param {number } start
24
+ * @param {number } end
25
+ * @return {number }
26
+ */
27
+ MyCalendarThree . prototype . book = function ( start , end ) {
28
+ let idx = find ( this . cals , start , 1 )
29
+ idx = find ( this . cals , end , - 1 )
30
+ let count = 0
31
+ let max = 0
32
+ for ( let cal of this . cals ) {
33
+ count += cal [ 1 ]
34
+ max = Math . max ( max , count )
35
+ }
36
+ return max
37
+ }
38
+
39
+ /**
40
+ * Your MyCalendarThree object will be instantiated and called as such:
41
+ * var obj = new MyCalendarThree()
42
+ * var param_1 = obj.book(start,end)
43
+ */
You can’t perform that action at this time.
0 commit comments