File tree Expand file tree Collapse file tree 1 file changed +39
-0
lines changed Expand file tree Collapse file tree 1 file changed +39
-0
lines changed Original file line number Diff line number Diff line change
1
+ import java .util .Collections ;
2
+ import java .util .Comparator ;
3
+ import java .util .List ;
4
+
5
+ class Interval {
6
+ int start , end ;
7
+
8
+ Interval (int start , int end ) {
9
+ this .start = start ;
10
+ this .end = end ;
11
+ }
12
+ }
13
+
14
+ class Solution {
15
+
16
+ public boolean canAttendMeetings (List <Interval > intervals ) {
17
+ Collections .sort (intervals , new Comparator <Interval >() {
18
+ @ Override
19
+ public int compare (Interval i1 , Interval i2 ) {
20
+ if (i1 .start == i2 .start ) {
21
+ return i1 .end - i2 .end ;
22
+ }
23
+
24
+ return i1 .start - i2 .start ;
25
+ }
26
+ });
27
+
28
+ int prevEnd = -987654321 ;
29
+ for (Interval anInt : intervals ) {
30
+ if (anInt .start < prevEnd ) {
31
+ return false ;
32
+ }
33
+
34
+ prevEnd = anInt .end ;
35
+ }
36
+
37
+ return true ;
38
+ }
39
+ }
You can’t perform that action at this time.
0 commit comments