Skip to content

252 Meeting Rooms

252. Meeting Rooms

题目: https://leetcode.com/problems/meeting-rooms/

难度 : Easy

思路:

学了一下如何根据attribute 来sort object intervals.sort(key = lambda interval : interval.start)

AC 代码

# Definition for an interval.
# class Interval(object):
#     def __init__(self, s=0, e=0):
#         self.start = s
#         self.end = e

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


回到顶部