Skip to content

Commit 59d7872

Browse files
authored
Update README_EN.md
1 parent 6a90290 commit 59d7872

File tree

1 file changed

+37
-0
lines changed

1 file changed

+37
-0
lines changed

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

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

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+
209246
<!-- tabs:end -->
210247

211248
<!-- solution:end -->

0 commit comments

Comments
 (0)