Skip to content

Commit 6cb5e42

Browse files
committed
feat(soobing): week14 > meeting-rooms-ii
1 parent e113687 commit 6cb5e42

File tree

1 file changed

+37
-0
lines changed

1 file changed

+37
-0
lines changed

β€Žmeeting-rooms-ii/soobing.tsβ€Ž

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
/**
2+
* 문제 μ„€λͺ…
3+
* - μ£Όμ–΄μ§„ νšŒμ˜μ‹œκ°„μ„ μ§„ν–‰ν•  수 μžˆλŠ” μ΅œμ†Œμ˜ νšŒμ˜μ‹œκ°„ 갯수 κ΅¬ν•˜κΈ°
4+
*
5+
* 아이디어
6+
* 1) minheap + greeday
7+
* - νšŒμ˜μ‹œκ°„ μ‹œμž‘μ‹œκ°„μœΌλ‘œ μ •λ ¬(회의 일정을 μ‹œκ°„ 순으둜 처리)
8+
* - Heapμ—λŠ” ν˜„μž¬ μ‚¬μš© 쀑인 νšŒμ˜μ‹€μ˜ μ’…λ£Œ μ‹œκ°„λ“€λ§Œ μ €μž₯
9+
* - 회의 μ‹œμž‘μ‹œκ°„μ΄ λμ‹œκ°„λ³΄λ‹€ κ°™κ±°λ‚˜ 크면 νšŒμ˜μ‹€ μ“Έμˆ˜ μžˆλŠ” κ±°λ‹ˆκΉŒ shift ν•΄μ„œ 회의 꺼냄
10+
* - νšŒμ˜μ‹œκ°„ 끝 μ‹œκ°„μ„ νž™μ— λ„£κ³ , λμ‹œκ°„ μ˜€λ¦„μ°¨μˆœμœΌλ‘œ μ •λ ¬(minheap)
11+
* - μ΅œμ’…μ μœΌλ‘œ heap의 크기 = ν•„μš”ν•œ νšŒμ˜μ‹€ 개수
12+
*/
13+
14+
type Interval = { start: number; end: number };
15+
16+
class Solution {
17+
minMeetingRooms(intervals: Interval[]): number {
18+
if (intervals.length === 0) return 0;
19+
20+
intervals.sort((a, b) => a.start - b.start);
21+
22+
const heap: number[] = [];
23+
24+
for (const interval of intervals) {
25+
const { start, end } = interval;
26+
27+
if (heap.length > 0 && heap[0] <= start) {
28+
heap.shift();
29+
}
30+
31+
heap.push(end);
32+
heap.sort((a, b) => a - b);
33+
}
34+
35+
return heap.length;
36+
}
37+
}

0 commit comments

Comments
Β (0)