Meeting Rooms

LintCode Q 920 - Meeting Rooms

Given an array of meeting time intervals consisting of start and end times [[s1,e1],[s2,e2],…], determine if a person could attend all meetings.

Example1
Input: intervals = [(0,30),(5,10),(15,20)] ; Output: false
Explanation:
(0,30), (5,10) and (0,30),(15,20) will conflict

Example2
Input: intervals = [(5,8),(9,15)] ; Output: true
Explanation:
Two times will not conflict

Solution

Code:

public boolean canAttendMeetings(List<Interval> intervals) {

	if (intervals.size() <= 1) return true;

	Collections.sort(intervals, (a,b) -> (a.end - b.end));

	int curEnd = intervals.get(0).end;

	for (int i = 1; i < intervals.size(); i++) {
		Interval interval = intervals.get(i);
		if (interval.start < curEnd)
			return false;
		else
			curEnd = interval.end;
	}

	return true;
}

   Reprint policy


《Meeting Rooms》 by Tong Shi is licensed under a Creative Commons Attribution 4.0 International License
 Previous
Meeting Rooms II Meeting Rooms II
LintCode Q 921 - Meeting Rooms IIGiven an array of meeting time intervals consisting of start and end times [[s1,e1],[s2
2019-05-25 Tong Shi
Next 
Assign Cookies Assign Cookies
LeetCode Q 455 - Assign CookiesAssume you are an awesome parent and want to give your children some cookies. But, you sh
2019-05-25 Tong Shi
  TOC