给定一个会议时间安排的数组,每个会议时间都会包括开始和结束的时间 [[s1,e1],[s2,e2],...]
(si < ei),请你判断一个人是否能够参加这里面的全部会议。
示例 1:
输入: [[0,30],[5,10],[15,20]]
输出: false
示例 2:
输入: [[7,10],[2,4]] 输出: true
思路:
先按开始时间排好序,然后看后一个的开始的时间是不是在前一个会议结束之前。
class Solution(object):
def canAttendMeetings(self, intervals):
"""
:type intervals: List[List[int]]
:rtype: bool
"""
intvs = sorted(intervals, key = lambda x: x[0])
for idx, intv in enumerate(intvs):
if idx > 0:
if intv[0] < intvs[idx - 1][1]:
return False
return True