Skip to content

Commit ce01867

Browse files
committed
meeting-rooms solution
1 parent 3fae094 commit ce01867

File tree

1 file changed

+44
-0
lines changed

1 file changed

+44
-0
lines changed

โ€Žmeeting-rooms/jdy8739.js

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
import {
2+
Interval,
3+
} from '/opt/node/lib/lintcode/index.js';
4+
5+
/**
6+
* Definition of Interval:
7+
* class Interval {
8+
* constructor(start, end) {
9+
* this.start = start;
10+
* this.end = end;
11+
* }
12+
* }
13+
*/
14+
15+
export class Solution {
16+
/**
17+
* @param intervals: an array of meeting time intervals
18+
* @return: if a person could attend all meetings
19+
*/
20+
canAttendMeetings(intervals) {
21+
const sort = intervals.sort((a, b) => {
22+
if (a[1] === b[1]) {
23+
return a[0] - b[0];
24+
}
25+
26+
return a[1] - b[1];
27+
})
28+
29+
for (let i = 0; i < sort.length - 2; i++) {
30+
const current = sort[i][1];
31+
const next = sort[i + 1][0];
32+
33+
if (current > next) {
34+
return false;
35+
}
36+
}
37+
38+
return true;
39+
}
40+
}
41+
42+
// ์‹œ๊ฐ„๋ณต์žก๋„ O(nlogn) -> sort ํ•จ์ˆ˜ ์‚ฌ์šฉ์œผ๋กœ ์ธํ•œ ์‹œ๊ฐ„๋ณต์žก๋„
43+
// ๊ณต๊ฐ„๋ณต์žก๋„ O(1) -> ์‚ฌ์šฉํ•˜๋Š” ์ž๋ฃŒ๊ตฌ์กฐ, ํ•จ์ˆ˜์‹คํ–‰์Šคํƒ ์—†์Œ
44+

0 commit comments

Comments
ย (0)