def canAttendMeetings(self, intervals):
intervals.sort(key=lambda x: x.start)
for i in range(1, len(intervals)):
if intervals[i].start < intervals[i1].end:
return False
return True
My Python Solution

Same, but using
all(...)
:def canAttendMeetings(self, intervals): intervals.sort(key=lambda i: i.start) return all(intervals[i1].end <= intervals[i].start for i in range(1, len(intervals)))
I like that it's shorter and that I can positively say what I want (
intervals[i1].end <= intervals[i].start
), not its negation.Another alternative:
def canAttendMeetings(self, intervals): intervals.sort(key=lambda i: i.start) return all(i.end <= j.start for i, j in zip(intervals, intervals[1:]))

@StefanPochmann @agave While I love the simplicity of the solution I think it suffers from a worst average case runtime compared to the solution posted by OP.