forked from liuyubobobo/Play-Leetcode
-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.cpp
44 lines (33 loc) · 951 Bytes
/
main.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
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
/// Source : https://leetcode.com/problems/meeting-rooms/description/
/// Author : liuyubobobo
/// Time : 2018-09-10
#include <iostream>
#include <vector>
using namespace std;
/// Brute Force see if overlapped for every two intervals
/// Time Complexity: O(n^2)
/// Space Complexity: O(1)
/// 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 {
public:
bool canAttendMeetings(vector<Interval>& intervals) {
for(int i = 0; i < intervals.size(); i ++)
for(int j = i + 1; j < intervals.size(); j ++)
if(overlapped(intervals[i], intervals[j]))
return false;
return true;
}
private:
bool overlapped(const Interval& i1, const Interval& i2){
return max(i1.start, i2.start) < min(i1.end, i2.end);
}
};
int main() {
return 0;
}