forked from Ayushsinhahaha/HacktoberFest
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMeeting_room.cpp
More file actions
36 lines (27 loc) · 768 Bytes
/
Copy pathMeeting_room.cpp
File metadata and controls
36 lines (27 loc) · 768 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
// LC 252. Meeting Rooms
/*
Given an array of meeting time intervals where intervals[i] = [starti, endi], determine if a person could attend all meetings.
Example 1:
Input: intervals = [[0,30],[5,10],[15,20]]
Output: false
Example 2:
Input: intervals = [[7,10],[2,4]]
Output: true
*/
// TC - O(NlogN), SC - O(1)
class Solution {
public:
bool canAttendMeetings(vector<Interval>& intervals) {
map<int, int> m;
for(int i = 0; i < intervals.size(); ++i){
m[intervals[i].start] = intervals[i].end;
}
if(m.size() < intervals.size()) return false;
int tmp = 0;
for (map<int,int>::iterator it=m.begin(); it!=m.end(); ++it){
if(tmp > it->first) return false;
tmp = it->second;
}
return true;
}
};