Skip to content

Commit 86579d9

Browse files
committed
#231 solution
1 parent 0e215d8 commit 86579d9

File tree

1 file changed

+44
-0
lines changed

1 file changed

+44
-0
lines changed

meeting-rooms/sungjinwi.cpp

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
/*
2+
풀이 :
3+
시작 시간 기준으로 intervals 정렬 후 반복문 돌면서 옆 구간과 겹치는 구간이 있으면 false 모두 안 겹치면 true
4+
5+
intervals 개수 : N
6+
7+
TC : O (N log N)
8+
정렬 시간복잡도
9+
10+
SC : O (1)
11+
*/
12+
13+
#include <vector>
14+
#include <algorithm>
15+
16+
using namespace std;
17+
18+
/**
19+
* Definition of Interval:
20+
* class Interval {
21+
* public:
22+
* int start, end;
23+
* Interval(int start, int end) {
24+
* this->start = start;
25+
* this->end = end;
26+
* }
27+
* }
28+
*/
29+
30+
class Solution {
31+
public:
32+
/**
33+
* @param intervals: an array of meeting time intervals
34+
* @return: if a person could attend all meetings
35+
*/
36+
bool canAttendMeetings(vector<Interval> &intervals) {
37+
sort(intervals.begin(), intervals.end(), [] (Interval& a, Interval& b) {return a.start <= b.start;});
38+
for (int i = 0; i < intervals.size() - 1; i++) {
39+
if (intervals[i].end > intervals[i + 1].start)
40+
return false;
41+
}
42+
return true;
43+
}
44+
};

0 commit comments

Comments
 (0)