Skip to content

Commit 599a7d8

Browse files
committed
Add week 13 solutions: meeting-rooms
1 parent c8d452b commit 599a7d8

File tree

1 file changed

+26
-0
lines changed

1 file changed

+26
-0
lines changed

meeting-rooms/gitsunmin.ts

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
/**
2+
* https://www.lintcode.com/problem/920/
3+
* time complexity : O(n log n)
4+
* space complexity : O(log n)
5+
*/
6+
7+
export class Interval {
8+
start: number;
9+
end: number;
10+
constructor(start: number, end: number) {
11+
this.start = start;
12+
this.end = end;
13+
}
14+
}
15+
g
16+
export function canAttendMeetings(intervals: Interval[]): boolean {
17+
intervals.sort((a, b) => a.start - b.start);
18+
19+
for (let i = 0; i < intervals.length - 1; i++) {
20+
const { end } = intervals[i];
21+
const { start: nextStart } = intervals[i + 1];
22+
23+
if (end > nextStart) return false;
24+
}
25+
return true;
26+
}

0 commit comments

Comments
 (0)