fork download
  1. #include<bits/stdc++.h>
  2. using namespace std;
  3. struct Interval {
  4. int start;
  5. int end;
  6. Interval() : start(0), end(0) {}
  7. Interval(int s, int e) : start(s), end(e) {}
  8. };
  9. class Solution
  10. {
  11. public:
  12. int minMeetingRooms(vector<Interval>& intervals) {
  13. map<int, int> changes;
  14. for (auto i : intervals)
  15. {
  16. changes[i.start] += 1;
  17. changes[i.end] -= 1;
  18. }
  19. int rooms = 0, maxrooms = 0;
  20. for (auto change : changes)
  21. {
  22. // cout<<change.second<<endl;
  23. maxrooms = max(maxrooms, rooms += change.second);
  24. }
  25. return maxrooms;
  26. }
  27. };
  28.  
  29. int main(void) {
  30. Solution solution;
  31. vector<Interval> intervals = {{1, 3}, {2, 4}, {3, 5}};
  32. cout << solution.minMeetingRooms(intervals) << "\tPassed\n";
  33. intervals.clear();
  34. //cout << solution.minMeetingRooms(intervals) << "\tPassed\n";
  35. // intervals = {{9, 10}, {4, 9}, {4, 17}};
  36. // cout << solution.minMeetingRooms(intervals) << "\tPassed\n";
  37. // cout << "\nPassed All\n";
  38. return 0;
  39. }
  40.  
Success #stdin #stdout 0s 15240KB
stdin
Standard input is empty
stdout
2	Passed