Meeting rooms#

Levels: level-4
Data structures: array
Patterns: intervals

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.

Example#

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

Python Solution#

 1import operator
 2
 3
 4class Interval:
 5    def __init__(self, s=0, e=0):
 6        self.start = s
 7        self.end = e
 8
 9
10class Solution:
11    def canAttendMeetings(self, intervals):
12        """
13        :type intervals: list[Interval]
14        :rtype: bool
15        """
16        intervals.sort(key=operator.attrgetter("start"))
17        for i in range(len(intervals) - 1):
18            if intervals[i].end > intervals[i + 1].start:
19                return False
20
21        return True