Solution 1

  • TimeO(n log n)
  • SpaceO(1)

where, n is the total number of intervals
Solved in 6 min, all by yourself! Good job!

Python
# Definition of Interval:
# class Interval(object):
#     def __init__(self, start, end):
#         self.start = start
#         self.end = end
class Solution:
    '''
    Time Complexity: O(n log n)
    Space Complexity: O(1)
    where, n is the total number of intervals
    Solved in 6 min, all by yourself! Good job!
    '''
    def canAttendMeetings(self, intervals: List[Interval]) -> bool:
        intervals.sort(key=lambda x: x.start)
        for i in range(len(intervals)-1):
            if intervals[i].end > intervals[i+1].start:
                return False
        return True
Leet Code/python.py · L3364–3382