Skip to content

Commit 0948a7c

Browse files
committed
add meeting rooms solution
1 parent c59747e commit 0948a7c

File tree

1 file changed

+40
-0
lines changed

1 file changed

+40
-0
lines changed

meeting-rooms/Tessa1217.java

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,42 @@
1+
import java.util.Collections;
2+
import java.util.List;
3+
4+
/**
5+
* Definition of Interval:
6+
* public class Interval {
7+
* int start, end;
8+
* Interval(int start, int end) {
9+
* this.start = start;
10+
* this.end = end;
11+
* }
12+
* }
13+
*/
14+
115
public class Solution {
16+
/**
17+
* @param intervals: an array of meeting time intervals
18+
* @return: if a person could attend all meetings
19+
*/
20+
21+
// 시간복잡도: O(n log n) - 정렬, 공간복잡도: O(1)
22+
public boolean canAttendMeetings(List<Interval> intervals) {
23+
// Write your code here
24+
25+
if (intervals == null || intervals.isEmpty()) return true;
26+
27+
Collections.sort(intervals, (i1, i2) -> i1.start - i2.start);
28+
29+
Interval previous = intervals.get(0);
30+
31+
for (int i = 1; i < intervals.size(); i++) {
32+
Interval current = intervals.get(i);
33+
if (previous.end > current.start) {
34+
return false;
35+
}
36+
previous = current;
37+
}
38+
39+
return true;
40+
}
241
}
42+

0 commit comments

Comments
 (0)