File tree Expand file tree Collapse file tree 3 files changed +85
-0
lines changed
solution/0700-0799/0729.My Calendar I Expand file tree Collapse file tree 3 files changed +85
-0
lines changed Original file line number Diff line number Diff line change @@ -256,6 +256,36 @@ impl MyCalendar {
256
256
}
257
257
```
258
258
259
+ #### JavaScript
260
+
261
+ ``` js
262
+ var MyCalendar = function () {
263
+ this .calendar = [];
264
+ };
265
+
266
+ /**
267
+ * @param {number} start
268
+ * @param {number} end
269
+ * @return {boolean}
270
+ */
271
+ MyCalendar .prototype .book = function (start , end ) {
272
+ for (const item of this .calendar ) {
273
+ if (end <= item[0 ] || item[1 ] <= start) {
274
+ continue ;
275
+ }
276
+ return false ;
277
+ }
278
+ this .calendar .push ([start, end]);
279
+ return true ;
280
+ };
281
+
282
+ /**
283
+ * Your MyCalendar object will be instantiated and called as such:
284
+ * var obj = new MyCalendar()
285
+ * var param_1 = obj.book(start,end)
286
+ */
287
+ ```
288
+
259
289
<!-- tabs:end -->
260
290
261
291
<!-- solution:end -->
Original file line number Diff line number Diff line change @@ -254,6 +254,36 @@ impl MyCalendar {
254
254
}
255
255
```
256
256
257
+ #### JavaScript
258
+
259
+ ``` js
260
+ var MyCalendar = function () {
261
+ this .calendar = [];
262
+ };
263
+
264
+ /**
265
+ * @param {number} start
266
+ * @param {number} end
267
+ * @return {boolean}
268
+ */
269
+ MyCalendar .prototype .book = function (start , end ) {
270
+ for (const item of this .calendar ) {
271
+ if (end <= item[0 ] || item[1 ] <= start) {
272
+ continue ;
273
+ }
274
+ return false ;
275
+ }
276
+ this .calendar .push ([start, end]);
277
+ return true ;
278
+ };
279
+
280
+ /**
281
+ * Your MyCalendar object will be instantiated and called as such:
282
+ * var obj = new MyCalendar()
283
+ * var param_1 = obj.book(start,end)
284
+ */
285
+ ```
286
+
257
287
<!-- tabs:end -->
258
288
259
289
<!-- solution:end -->
Original file line number Diff line number Diff line change
1
+ var MyCalendar = function ( ) {
2
+ this . calendar = [ ] ;
3
+ } ;
4
+
5
+ /**
6
+ * @param {number } start
7
+ * @param {number } end
8
+ * @return {boolean }
9
+ */
10
+ MyCalendar . prototype . book = function ( start , end ) {
11
+ for ( const item of this . calendar ) {
12
+ if ( end <= item [ 0 ] || item [ 1 ] <= start ) {
13
+ continue ;
14
+ }
15
+ return false ;
16
+ }
17
+ this . calendar . push ( [ start , end ] ) ;
18
+ return true ;
19
+ } ;
20
+
21
+ /**
22
+ * Your MyCalendar object will be instantiated and called as such:
23
+ * var obj = new MyCalendar()
24
+ * var param_1 = obj.book(start,end)
25
+ */
You can’t perform that action at this time.
0 commit comments