회의 시간 간격의 배열이 있다고 가정합니다. 두 번 시작 및 종료 시간[[s1,e1],[s2,e2],...]이 있으며 각 쌍은 규칙(si
따라서 입력이 [[0, 30], [5, 10], [15, 20]]과 같으면 출력은 2가 됩니다.
이 문제를 해결하기 위해 다음 단계를 따릅니다. −
-
하나의 우선순위 큐 pq 정의
-
간격 배열 정렬
-
ret :=0
-
initialize i :=0의 경우, i <간격의 크기일 때 업데이트(i를 1만큼 증가), 수행 -
-
동안(pq가 비어 있지 않고 pq <=interval[i, 0]의 최상위 요소), −
-
pq에서 요소 삭제
-
-
pq에 간격[i] 삽입
-
ret :=ret의 최대값과 pq의 크기
-
-
리턴 렛
예시
더 나은 이해를 위해 다음 구현을 살펴보겠습니다. −
#include <bits/stdc++.h> using namespace std; struct Comparator{ bool operator()(vector <int<& a, vector <int<& b){ return !(a[1] < b[1]); } }; class Solution { public: static bool cmp(vector <int< a, vector <int< b){ return (a[1] < b[1]); } int minMeetingRooms(vector<vector<int<>& intervals) { priority_queue<vector<int<, vector<vector<int< >, Comparator> pq; sort(intervals.begin(), intervals.end()); int ret = 0; for (int i = 0; i < intervals.size(); i++) { while (!pq.empty() && pq.top()[1] <= intervals[i][0]) pq.pop(); pq.push(intervals[i]); ret = max(ret, (int)pq.size()); } return ret; } }; main(){ vector<vector<int<> v = {{0, 30}, {5, 10}, {15, 20}}; Solution ob; cout << (ob.minMeetingRooms(v)); }
입력
{{0, 30}, {5, 10}, {15, 20}}
출력
2