File tree Expand file tree Collapse file tree 1 file changed +9
-18
lines changed
src/main/java/com/fishercoder/solutions Expand file tree Collapse file tree 1 file changed +9
-18
lines changed Original file line number Diff line number Diff line change 1
1
package com .fishercoder .solutions ;
2
2
3
- import java .util .ArrayList ;
4
- import java .util .Collections ;
5
- import java .util .List ;
3
+ import java .util .Arrays ;
6
4
7
5
public class _252 {
8
6
public static class Solution1 {
9
7
public boolean canAttendMeetings (int [][] intervals ) {
10
-
11
- List <int []> list = new ArrayList ();
12
- for (int [] interval : intervals ) {
13
- list .add (interval );
8
+ if (intervals == null || intervals .length == 0 ) {
9
+ return true ;
14
10
}
15
-
16
- Collections .sort (list , (o1 , o2 ) -> {
17
- if (o1 [0 ] > o2 [0 ]) {
18
- return 1 ;
19
- } else {
20
- return -1 ;
21
- }
22
- });
23
-
24
- for (int i = 0 ; i < list .size () - 1 ; i ++) {
25
- if (list .get (i )[1 ] > list .get (i + 1 )[0 ]) {
11
+ Arrays .sort (intervals , (a , b ) -> a [0 ] - b [0 ]);
12
+ int end = intervals [0 ][1 ];
13
+ for (int i = 1 ; i < intervals .length ; i ++) {
14
+ if (intervals [i ][0 ] < end ) {
26
15
return false ;
16
+ } else {
17
+ end = intervals [i ][1 ];
27
18
}
28
19
}
29
20
return true ;
You can’t perform that action at this time.
0 commit comments