File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1+
2+ # https://neetcode.io/problems/meeting-schedule/question
3+ # Related Question
4+ # https://leetcode.com/problems/non-overlapping-intervals/description/
5+ # μ΄μ μ νμλ λ¬Έμ μ μλΉν λΉμ·νλ€κ³ μκ°ν΄μ ν΄λΉ λ¬Έμ λ₯Ό νμλ νμ΄λλ‘ νμλ€.
6+ # 1. Sort the input by start time
7+ # 2. Track the previous interval's end time
8+ # 3. Check if the current interval's start overlaps with the previous end
9+ # Time complexity: O(n log n)
10+ class Solution :
11+ def canAttendMeetings (self , intervals : List [Interval ]) -> bool :
12+ # Write your code here
13+ if not intervals :
14+ return True
15+
16+ intervals .sort (key = lambda x : x .start )
17+
18+ prev = intervals [0 ].end
19+
20+ for i in intervals [1 :]:
21+ if i .start >= prev :
22+ prev = i .end
23+ else :
24+ return False
25+ return True
26+ # for i in range(1, len(intervals)):
27+ # i1 = intervals[i-1]
28+ # i2 = intervals[i]
29+
30+ # if i1.end > i2.start:
31+ # return False
You canβt perform that action at this time.
0 commit comments