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