-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path252.cpp
More file actions
31 lines (27 loc) · 669 Bytes
/
252.cpp
File metadata and controls
31 lines (27 loc) · 669 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
/*
* Written by Nitin Kumar Maharana
* nitin.maharana@gmail.com
*/
/**
* Definition for an interval.
* struct Interval {
* int start;
* int end;
* Interval() : start(0), end(0) {}
* Interval(int s, int e) : start(s), end(e) {}
* };
*/
class Solution {
static bool compare(Interval a, Interval b)
{
return (a.start < b.start);
}
public:
bool canAttendMeetings(vector<Interval>& intervals) {
sort(intervals.begin(), intervals.end(), compare);
for(int i = 1; i < intervals.size(); i++)
if(intervals[i-1].end > intervals[i].start)
return false;
return true;
}
};