Skip to content

Latest commit

 

History

History
50 lines (33 loc) · 1.05 KB

0252._Meeting_Rooms.md

File metadata and controls

50 lines (33 loc) · 1.05 KB

252. Meeting Rooms

难度: Easy

刷题内容

原题连接

内容描述

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.

Example 1:

Input: [[0,30],[5,10],[15,20]]
Output: false
Example 2:

Input: [[7,10],[2,4]]
Output: true

解题方案

思路 1

排个序然后看看后面meeting的start会不会比前面meeting的end小,如果有立刻就返回False,全都没有那就返回True

class Solution(object):
    def canAttendMeetings(self, intervals):
        """
        :type intervals: List[Interval]
        :rtype: bool
        """
        if not intervals or len(intervals) < 2:
            return True
        intervals = sorted(intervals, key=lambda x:(x.start, x.end))
        for i in range(1, len(intervals)):
            if intervals[i].start < intervals[i-1].end:
                return False
        return True