其他分享
首页 > 其他分享> > [LeetCode] 252. Meeting Rooms_Easy tag: Sort

[LeetCode] 252. Meeting Rooms_Easy tag: Sort

作者:互联网

Given an array of meeting time intervals where intervals[i] = [starti, endi], determine if a person could attend all meetings.

 

Example 1:

Input: intervals = [[0,30],[5,10],[15,20]]
Output: false

Example 2:

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

 

Constraints:

 

Ideas: 这个题目实际上跟[LeetCode] 56. Merge Intervals_Medium Tag: sort 类似, 就是看看是否有重合。

Code: 

class Solution:
    def canAttendMeetings(self, intervals: List[List[int]]) -> bool:
        intervals.sort(key= lambda x: x[0])
        for i in range(1, len(intervals)):
            if intervals[i][0] < intervals[i - 1][1]:
                return False
        return True

 

标签:Sort,sort,return,List,intervals,tag,Rooms,Input,LeetCode
来源: https://www.cnblogs.com/Johnsonxiong/p/15073435.html