[[s1,e1],[s2,e2],...]
(si < ei), find the minimum number of conference rooms required.For example,
Given
[[0, 30],[5, 10],[15, 20]]
,return
2
./**
* Definition for an interval.
* public class Interval {
* int start;
* int end;
* Interval() { start = 0; end = 0; }
* Interval(int s, int e) { start = s; end = e; }
* }
*/
public class Solution {
public int minMeetingRooms(Interval[] intervals) {
if (intervals == null || intervals.length == 0) {
return 0;
}
Arrays.sort(intervals, new Comparator<Interval>() {
public int compare(Interval i1, Interval i2) {
return i1.start - i2.start;
}
});
List<Interval> list = new ArrayList<Interval>();
list.add(intervals[0]);
for (int i = 1; i < intervals.length; i++) {
Interval inter = intervals[i];
boolean find = false;
for (Interval tmp : list) {
if (inter.start >= tmp.end) {
tmp.start = inter.start;
tmp.end = inter.end;
find = true;
break;
}
}
if (!find) {
list.add(inter);
}
}
return list.size();
}
}
没有评论:
发表评论