Skip to content

Commit eb43dc4

Browse files
authored
Merge pull request #2315 from doh6077/main
[doh6077] WEEK 13 solutions
2 parents e0649f0 + 360545e commit eb43dc4

1 file changed

Lines changed: 31 additions & 0 deletions

File tree

β€Žmeeting-rooms/doh6077.pyβ€Ž

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
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

0 commit comments

Comments
Β (0)