Description
Given an array of meeting time intervals consisting of start and end times [[s1,e1],[s2,e2],...] (si < ei), 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
Solution
easier than Meeting-Room 2
"""
Definition of Interval.
class Interval(object):
def __init__(self, start, end):
self.start = start
self.end = end
"""
import heapq
class Solution:
"""
@param intervals: an array of meeting time intervals
@return: if a person could attend all meetings
"""
def canAttendMeetings(self, intervals):
# Write your code here
if len(intervals) ==0:
return True
s_inter = sorted(intervals,key= lambda x:x.start)
heap = [s_inter[0].end] # catch the eariest end time
for s in s_inter[1:]:
if heap[0] <= s.start:
heapq.heappop(heap)
heapq.heappush(heap,s.end)
else:
return False
return True