严氏北美IT公司面试真题汇总和解答论坛
Would you like to react to this message? Create an account in a few clicks or log in to continue.

Meeting Room II leetcode原题

Go down

Meeting Room II leetcode原题 Empty Meeting Room II leetcode原题

Post by Admin Sun Oct 22, 2017 2:34 pm

public int minMeetingRooms(Interval[] intervals) {
Arrays.sort ( intervals, new Comparator<Interval>(){
public int compare ( Interval int1, Interval int2 ){
return int1.start - int2.start;
}
});
PriorityQueue <Interval> que = new PriorityQueue<Interval>( new Comparator<Interval>(){
public int compare ( Interval int1, Interval int2 ){
return int1.end - int2.end;
}
});
int rooms = 0;
for ( int i = 0; i < intervals.length; i ++ ){
while ( !que.isEmpty() && que.peek().end <= intervals[ i ].start ){
que.poll();
}
que.offer ( intervals[ i ] );
rooms = Math.max ( rooms, que.size() );
}
return rooms;
}

Admin
Admin

Posts : 124
Join date : 2017-10-21

https://csinterviewquestions.forumotion.com

Back to top Go down

Back to top

- Similar topics

 
Permissions in this forum:
You cannot reply to topics in this forum