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+
27+
28+ # for i in range(1, len(intervals)):
29+ # i1 = intervals[i-1]
30+ # i2 = intervals[i]
31+
32+ # if i1.end > i2.start:
33+ # return False
You canโt perform that action at this time.
0 commit comments