File tree Expand file tree Collapse file tree 1 file changed +41
-0
lines changed
Expand file tree Collapse file tree 1 file changed +41
-0
lines changed Original file line number Diff line number Diff line change 1+ /**
2+ * Definition of Interval:
3+ * class Interval {
4+ * constructor(start, end) {
5+ * this.start = start;
6+ * this.end = end;
7+ * }
8+ * }
9+ */
10+
11+ class Solution {
12+ /**
13+ * @param {Interval[] } intervals
14+ * @returns {number }
15+ */
16+ minMeetingRooms ( intervals ) {
17+ if ( ! intervals || intervals . length === 0 ) return 0 ;
18+
19+ intervals . sort ( ( a , b ) => a . start - b . start ) ;
20+
21+ let rooms = [ ] ;
22+
23+ for ( let i = 0 ; i < intervals . length ; i ++ ) {
24+ let assigned = false ;
25+
26+ for ( let j = 0 ; j < rooms . length ; j ++ ) {
27+ if ( rooms [ j ] <= intervals [ i ] . start ) {
28+ rooms [ j ] = intervals [ i ] . end ;
29+ assigned = true ;
30+ break ;
31+ }
32+ }
33+
34+ if ( ! assigned ) {
35+ rooms . push ( intervals [ i ] . end ) ;
36+ }
37+ }
38+
39+ return rooms . length ;
40+ }
41+ }
You can’t perform that action at this time.
0 commit comments