Skip to content

Commit d51396c

Browse files
committed
Meeting rooms solution
1 parent 84ad16d commit d51396c

1 file changed

Lines changed: 33 additions & 0 deletions

File tree

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

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

0 commit comments

Comments
ย (0)