252. Meeting Rooms

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
# 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
        """
        if not intervals: return True

        intervals.sort(key=lambda x: x.start)

        for i, interval in enumerate(intervals[1:]):
            if interval.start < intervals[i].end:
                return False
        return True
class Solution(object):
    def canAttendMeetings(self, intervals):
        """
        :type intervals: List[Interval]
        :rtype: bool
        """
        return all([first.end <= second.start for first, second in 
                zip(sorted(intervals, key = lambda x: x.start), sorted(intervals, key = lambda x: x.start)[1:])
                   ]) if intervals else True

results matching ""

    No results matching ""