-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmeeting_rooms.py
More file actions
32 lines (24 loc) · 908 Bytes
/
meeting_rooms.py
File metadata and controls
32 lines (24 loc) · 908 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
# https://www.lintcode.com/problem/meeting-rooms/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.
"""
>>> Solution().canAttendMeetings([Interval(0, 30), Interval(5, 10), Interval(15, 20)])
False
>>> Solution().canAttendMeetings([Interval(5, 8), Interval(9, 15)])
True
"""
class Interval(object):
def __init__(self, start, end):
self.start = start
self.end = end
class Solution:
"""
@param intervals: an array of meeting time intervals
@return: if a person could attend all meetings
"""
def canAttendMeetings(self, intervals):
intervals.sort(key=lambda interval: interval.start)
for i in range(1, len(intervals)):
if intervals[i].start < intervals[i - 1].end:
return False
return True