forked from fishercoder1534/Leetcode
-
Notifications
You must be signed in to change notification settings - Fork 0
/
_252.java
34 lines (28 loc) · 882 Bytes
/
_252.java
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
package com.fishercoder.solutions;
import com.fishercoder.common.classes.Interval;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
public class _252 {
public static class Solution1 {
public boolean canAttendMeetings(Interval[] intervals) {
List<Interval> list = new ArrayList();
for (Interval interval : intervals) {
list.add(interval);
}
Collections.sort(list, (o1, o2) -> {
if (o1.start > o2.start) {
return 1;
} else {
return -1;
}
});
for (int i = 0; i < list.size() - 1; i++) {
if (list.get(i).end > list.get(i + 1).start) {
return false;
}
}
return true;
}
}
}