Skip to content

Commit 909f08f

Browse files
committed
meeting rooms solution
1 parent b82ace8 commit 909f08f

File tree

1 file changed

+37
-0
lines changed

1 file changed

+37
-0
lines changed

β€Žmeeting-rooms/byol-han.js

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
import { Interval } from '/opt/node/lib/lintcode/index.js';
2+
3+
/**
4+
* https://www.lintcode.com/problem/920/
5+
* Definition of Interval:
6+
* class Interval {
7+
* constructor(start, end) {
8+
* this.start = start;
9+
* this.end = end;
10+
* }
11+
* }
12+
*/
13+
14+
export class Solution {
15+
/**
16+
* @param intervals: an array of meeting time intervals
17+
* @return: if a person could attend all meetings
18+
*/
19+
canAttendMeetings(intervals) {
20+
// λ¨Όμ € 회의λ₯Ό μ‹œμž‘ μ‹œκ°„ κΈ°μ€€μœΌλ‘œ μ •λ ¬ν•©λ‹ˆλ‹€.
21+
intervals.sort((a, b) => a[0] - b[0]);
22+
23+
// μ •λ ¬λœ νšŒμ˜λ“€μ„ 순차적으둜 λΉ„κ΅ν•˜λ©° κ²ΉμΉ˜λŠ”μ§€ ν™•μΈν•©λ‹ˆλ‹€.
24+
for (let i = 1; i < intervals.length; i++) {
25+
const prevEnd = intervals[i - 1][1]; // 이전 회의의 끝 μ‹œκ°„
26+
const currStart = intervals[i][0]; // ν˜„μž¬ 회의의 μ‹œμž‘ μ‹œκ°„
27+
28+
// 이전 회의의 끝 μ‹œκ°„λ³΄λ‹€ ν˜„μž¬ 회의의 μ‹œμž‘ μ‹œκ°„μ΄ λΉ λ₯΄λ©΄ κ²ΉμΉ©λ‹ˆλ‹€.
29+
if (currStart < prevEnd) {
30+
return false;
31+
}
32+
}
33+
34+
// κ²ΉμΉ˜λŠ” νšŒμ˜κ°€ μ—†μœΌλ©΄ trueλ₯Ό λ°˜ν™˜ν•©λ‹ˆλ‹€.
35+
return true;
36+
}
37+
}

0 commit comments

Comments
Β (0)