Created
October 28, 2019 20:47
-
-
Save criskgl/d8e37570e8b7a5ba6e784f298575df20 to your computer and use it in GitHub Desktop.
### Explanation <img src="https://i.loli.net/2018/09/24/5ba81e5ea9d15.jpg">
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
public int minMeetingRooms(int[][] intervals) { | |
int n = intervals.length; | |
int[] start = new int[n]; | |
int[] end = new int[n]; | |
for(int i = 0; i < n; i++){ | |
start[i] = intervals[i][0]; | |
end[i] = intervals[i][1]; | |
} | |
Arrays.sort(start); | |
Arrays.sort(end); | |
int endItr = 0; | |
int rooms = 0; | |
for(int i = 0; i < n; i++){ | |
//meeting is starting before the ending of another? | |
if(start[i] < end[endItr]){ | |
rooms++;//if so, we need one more room! | |
} | |
//meeting starting after(or just after) other ends. No need for another room | |
else if(start[i] >= end[endItr]){ | |
endItr++;//update next ending | |
} | |
} | |
return rooms; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment