Created
August 16, 2015 13:04
-
-
Save xynophon/aea781e6306f5c8c43eb to your computer and use it in GitHub Desktop.
LeetCode Meeting Rooms
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import java.util.*; | |
| public class MeetingRooms { | |
| public class Interval { | |
| int start; | |
| int end; | |
| Interval() { | |
| start = 0; | |
| end = 0; | |
| } | |
| Interval(int s, int e) { | |
| start = s; | |
| end = e; | |
| } | |
| } | |
| public boolean canAttendMeetings(Interval[] intervals) { | |
| Arrays.sort(intervals, new Comparator<Interval>() { | |
| @Override | |
| public int compare(Interval o1, Interval o2) { | |
| return o1.start - o2.start; | |
| } | |
| }); | |
| for (int i = 0; i < intervals.length - 1; i++) { | |
| if (intervals[i].end > intervals[i + 1].start) { | |
| return false; | |
| } | |
| } | |
| return true; | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment