File tree Expand file tree Collapse file tree 1 file changed +37
-0
lines changed
Expand file tree Collapse file tree 1 file changed +37
-0
lines changed Original file line number Diff line number Diff line change 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+ }
You canβt perform that action at this time.
0 commit comments