Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 2913062

Browse files
feat: add js solution to lc problem: No.0729 (#3566)
1 parent 2c96c8e commit 2913062

File tree

3 files changed

+85
-0
lines changed

3 files changed

+85
-0
lines changed

‎solution/0700-0799/0729.My Calendar I/README.md‎

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -256,6 +256,36 @@ impl MyCalendar {
256256
}
257257
```
258258

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+
259289
<!-- tabs:end -->
260290

261291
<!-- solution:end -->

‎solution/0700-0799/0729.My Calendar I/README_EN.md‎

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -254,6 +254,36 @@ impl MyCalendar {
254254
}
255255
```
256256

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+
257287
<!-- tabs:end -->
258288

259289
<!-- solution:end -->
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
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+
*/

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /