Skip to content

Commit 62fca0d

Browse files
committed
Meeting Rooms
1 parent c8d452b commit 62fca0d

File tree

1 file changed

+17
-0
lines changed

1 file changed

+17
-0
lines changed

meeting-rooms/TonyKim9401.java

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
// TC: O(n log n)
2+
// list sort
3+
// SC: O(n)
4+
// list sort max use O(n)
5+
public class Solution {
6+
public boolean canAttendMeetings(List<Interval> intervals) {
7+
intervals.sort(Comparator.comparingInt(o -> o.start));
8+
9+
for (int i = 0; i < intervals.size() - 1; i++) {
10+
Interval preInterval = intervals.get(i);
11+
Interval postInterval = intervals.get(i+1);
12+
13+
if (preInterval.end > postInterval.start) return false;
14+
}
15+
return true;
16+
}
17+
}

0 commit comments

Comments
 (0)