Created
January 4, 2016 00:27
-
-
Save ducalpha/87cefd314c9e858acb5c to your computer and use it in GitHub Desktop.
Check valid schedule
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
| struct Meeting { | |
| int start, end; | |
| }; | |
| struct CompareMeeting { | |
| bool operator()(const Meeting& a, const Meeting& b) const { | |
| if (a.start == b.start) return a.end < b.end; | |
| return a.start < b.start; | |
| } | |
| }; | |
| bool IsValidSchedule(vector<Meeting> meetings) { | |
| sort(meetings.begin(), meetings.end(), CompareMeeting); | |
| for (int i = 1; i < meetings.size(); ++i) { | |
| if (meetings[i - 1].end > meeting[i].start) | |
| return false; | |
| } | |
| return true; | |
| } // O(nlogn) time, O(n) space |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment