-
-
Notifications
You must be signed in to change notification settings - Fork 298
/
Copy path252.cpp
26 lines (26 loc) · 1.13 KB
/
252.cpp
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
__________________________________________________________________________________________________
class Solution {
public:
bool canAttendMeetings(vector<Interval>& intervals) {
for (int i = 0; i < intervals.size(); ++i) {
for (int j = i + 1; j < intervals.size(); ++j) {
if ((intervals[i].start >= intervals[j].start && intervals[i].start < intervals[j].end) || (intervals[j].start >= intervals[i].start && intervals[j].start < intervals[i].end)) return false;
}
}
return true;
}
};
__________________________________________________________________________________________________
class Solution {
public:
bool canAttendMeetings(vector<Interval>& intervals) {
sort(intervals.begin(), intervals.end(), [](const Interval &a, const Interval &b){return a.start < b.start;});
for (int i = 1; i < intervals.size(); ++i) {
if (intervals[i].start < intervals[i - 1].end) {
return false;
}
}
return true;
}
};
__________________________________________________________________________________________________