File tree Expand file tree Collapse file tree 1 file changed +37
-0
lines changed Expand file tree Collapse file tree 1 file changed +37
-0
lines changed Original file line number Diff line number Diff line change
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
+ }
You canβt perform that action at this time.
0 commit comments