Skip to content

Commit bb93040

Browse files
committed
feat: add meeting rooms solution
1 parent cbfa244 commit bb93040

File tree

1 file changed

+22
-0
lines changed

1 file changed

+22
-0
lines changed

β€Žmeeting-rooms/mangodm-web.py

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
from typing import List
2+
3+
4+
class Solution:
5+
def canAttendMeetings(self, intervals: List[List[int]]) -> bool:
6+
"""
7+
- Idea: λͺ¨λ“  νšŒμ˜μ— 참석할 수 있으렀면, μ•žμ„œ μ˜€λŠ” νšŒμ˜κ°€ λλ‚˜λŠ” μ‹œκ°„μ΄
8+
λ‹€μŒ 회의의 μ‹œμž‘ μ‹œκ°„μ„ λ„˜μ–΄μ„œλŠ” μ•ˆλœλ‹€.
9+
이λ₯Ό ν™•μΈν•˜κΈ° μœ„ν•΄ μ£Όμ–΄μ§„ 회의 일정을 μ‹œμž‘ μ‹œκ°„ κΈ°μ€€μœΌλ‘œ μ •λ ¬ν•˜κ³ ,
10+
순차적으둜 λΉ„κ΅ν•˜μ—¬ μœ„μ˜ 쑰건을 μœ„λ°˜ν•˜λŠ” νšŒμ˜κ°€ μžˆλŠ”μ§€ ν™•μΈν•œλ‹€.
11+
- Time Complexity: O(nlogn). n은 회의의 수.
12+
정렬에 O(nlogn)이 μ†Œμš”λ˜κ³ , 순차 탐색을 ν•˜λŠ” λ°λŠ” O(n)이 ν•„μš”ν•˜λ‹€.
13+
- Space Complexity: O(1).
14+
μΆ”κ°€ 곡간은 μ‚¬μš©ν•˜μ§€ μ•ŠλŠ”λ‹€.
15+
"""
16+
intervals.sort()
17+
18+
for i in range(len(intervals) - 1):
19+
if intervals[i][1] > intervals[i + 1][0]:
20+
return False
21+
22+
return True

0 commit comments

Comments
Β (0)