-
Notifications
You must be signed in to change notification settings - Fork 0
/
MeetingRooms.java
38 lines (30 loc) · 937 Bytes
/
MeetingRooms.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
package lintcode;
import java.util.Collections;
import java.util.Comparator;
import java.util.List;
class Interval {
int start, end;
Interval(int start, int end) {
this.start = start;
this.end = end;
}
}
public class MeetingRooms {
public boolean canAttendMeetings(List<Interval> intervals) {
// Write your code here
Collections.sort(intervals, new Comparator<Interval>() {
@Override
public int compare(Interval o1, Interval o2) {
return o1.start - o2.start;
}
});
int end = intervals.get(0).end;
for (int i=0; i< intervals.size(); i++){
if(end > intervals.get(i).start){
return false;
}
end = Math.max(end, intervals.get(i).end);
}
return true;
}
}