- 76ms
- 93%
- time: O(nlgn)
- space: O(1)
from functools import cmp_to_key
def cmp(a, b):
if a[0]==b[0]:
return [-1, 1][a[1]>b[1]]
return [-1, 1][a[0]>b[0]]
class Solution:
def canAttendMeetings(self, intervals: List[List[int]]) -> bool:
intervals.sort(key=cmp_to_key(cmp))
for i in range(1, len(intervals)):
if intervals[i][0] < intervals[i-1][1]:
return False
return True
- 40ms
- 98%
- time: O(nlgn)
- space: O(1)
class Solution:
def canAttendMeetings(self, intervals: List[List[int]]) -> bool:
intervals.sort(key=lambda x: x[0])
for i in range(1, len(intervals)):
if intervals[i][0] < intervals[i-1][1]:
return False
return True