ID | Title | Difficulty | |
---|---|---|---|
Loading... |
252. Meeting Rooms
Easy
LeetCode
Array, Sorting
Problem
Given an array of meeting time intervals
where $intervals[i] = [start_i, end_i]$, determine if a person could attend all meetings.
Example 1:
Input: [[0,30],[5,10],[15,20]]
Output: false
Example 2:
Input: [[7,10],[2,4]]
Output: true
Constraints:
- $0 <= intervals.length <= 10^4$
- $intervals[i].length == 2$
- $0 <= start_i < end_i <= 10^6$
Code
class Solution {
public boolean canAttendMeetings(int[][] intervals) {
Arrays.sort(intervals, (a, b) -> a[0] - b[0]);
int lastEnd = -1;
for(int[] inter : intervals) {
if(inter[0] < lastEnd) {
return false;
}
lastEnd = inter[1];
}
return true;
}
}
class Solution:
def canAttendMeetings(self, intervals: List[List[int]]) -> bool:
intervals.sort()
for i in range(1, len(intervals)):
if intervals[i][0] < intervals[i-1][1]:
return False
return True
按 <- 键看上一题!
251. Flatten 2D Vector
按 -> 键看下一题!
253. Meeting Rooms II