File tree Expand file tree Collapse file tree 1 file changed +35
-0
lines changed Expand file tree Collapse file tree 1 file changed +35
-0
lines changed Original file line number Diff line number Diff line change 1+ /* *
2+ * Definition of Interval:
3+ * class Interval {
4+ * var start: Int = 0
5+ * var end: Int = 0
6+ * constructor(start: Int, end: Int) {
7+ * this.start = start
8+ * this.end = end
9+ * }
10+ * }
11+ */
12+
13+ class Solution {
14+ /* *
15+ * @param intervals: an array of meeting time intervals
16+ * @return: the minimum number of conference rooms required
17+ */
18+ fun minMeetingRooms (intervals : List <Interval ?>): Int {
19+ // Write your code here
20+ val points = mutableListOf<List <Int >>()
21+ intervals.filterNotNull() // T(n) = O(nlogn)
22+ .forEach {
23+ points.add(listOf (it.start, 1 ,))
24+ points.add(listOf (it.end, - 1 ,))
25+ }
26+ var ans = 0
27+ var cnt = 0
28+ points.sortedBy {it[0 ]} // T(n) = S(n) = O(n)
29+ .forEach {
30+ cnt + = it[1 ]
31+ ans = maxOf(ans, cnt,)
32+ }
33+ return ans
34+ }
35+ }
You can’t perform that action at this time.
0 commit comments