Skip to content

Commit 6a90290

Browse files
authored
Update README.md
1 parent 5ac3684 commit 6a90290

File tree

1 file changed

+37
-0
lines changed
  • solution/0700-0799/0731.My Calendar II

1 file changed

+37
-0
lines changed

solution/0700-0799/0731.My Calendar II/README.md

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -208,6 +208,43 @@ func (this *MyCalendarTwo) Book(start int, end int) bool {
208208
*/
209209
```
210210

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+
211248
<!-- tabs:end -->
212249

213250
<!-- solution:end -->

0 commit comments

Comments
 (0)