File tree Expand file tree Collapse file tree 1 file changed +37
-0
lines changed
solution/0700-0799/0731.My Calendar II Expand file tree Collapse file tree 1 file changed +37
-0
lines changed Original file line number Diff line number Diff line change @@ -206,6 +206,43 @@ func (this *MyCalendarTwo) Book(start int, end int) bool {
206
206
*/
207
207
```
208
208
209
+ #### JavaScript
210
+
211
+ ``` js
212
+ var MyCalendarTwo = function () {
213
+ this .events = [];
214
+ this .overlaps = [];
215
+ };
216
+
217
+ /**
218
+ * @param {number} start
219
+ * @param {number} end
220
+ * @return {boolean}
221
+ */
222
+ MyCalendarTwo .prototype .book = function (start , end ) {
223
+ for (let [s, e] of this .overlaps ) {
224
+ if (Math .max (start, s) < Math .min (end, e)) {
225
+ return false ;
226
+ }
227
+ }
228
+
229
+ for (let [s, e] of this .events ) {
230
+ if (Math .max (start, s) < Math .min (end, e)) {
231
+ this .overlaps .push ([Math .max (start, s), Math .min (end, e)]);
232
+ }
233
+ }
234
+
235
+ this .events .push ([start, end]);
236
+ return true ;
237
+ };
238
+
239
+ /**
240
+ * Your MyCalendarTwo object will be instantiated and called as such:
241
+ * var obj = new MyCalendarTwo()
242
+ * var param_1 = obj.book(start,end)
243
+ */
244
+ ```
245
+
209
246
<!-- tabs:end -->
210
247
211
248
<!-- solution:end -->
You can’t perform that action at this time.
0 commit comments