package com.fishercoder.solutions;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

public class _252 {
    public static class Solution1 {
        public boolean canAttendMeetings(int[][] intervals) {

            List<int[]> list = new ArrayList();
            for (int[] interval : intervals) {
                list.add(interval);
            }

            Collections.sort(list, (o1, o2) -> {
                if (o1[0] > o2[0]) {
                    return 1;
                } else {
                    return -1;
                }
            });

            for (int i = 0; i < list.size() - 1; i++) {
                if (list.get(i)[1] > list.get(i + 1)[0]) {
                    return false;
                }
            }
            return true;
        }
    }
}

@@ -55,65 +55,9 @@
 rray
-List;%0Aimport java.util.Collections;%0Aimport java.util.List
+s
 ;%0A%0Ap
@@ -173,17 +173,16 @@
 vals) %7B%0A
-%0A
         
@@ -189,87 +189,54 @@
     
-List%3Cint%5B%5D%3E list = new ArrayList();%0A            for (int%5B%5D interval : intervals
+if (intervals == null %7C%7C intervals.length == 0
 ) %7B%0A
@@ -255,26 +255,19 @@
     
-list.add(interval)
+return true
 ;%0A  
@@ -278,17 +278,16 @@
       %7D%0A
-%0A
         
@@ -294,185 +294,195 @@
     
-Collections.sort(list, (o1, o2) -%3E %7B%0A                if (o1%5B0%5D %3E o2%5B0%5D) %7B%0A                    return 1;%0A                %7D else %7B%0A                    return -1;%0A                %7D
+Arrays.sort(intervals, (a, b) -%3E a%5B0%5D - b%5B0%5D);%0A            int end = intervals%5B0%5D%5B1%5D;%0A            for (int i = 1; i %3C intervals.length; i++) %7B%0A                if (intervals%5Bi%5D%5B0%5D %3C end) %7B
 %0A   
@@ -493,14 +493,8 @@
     
- %7D);%0A%0A
     
@@ -502,111 +502,44 @@
     
-   for (int i = 0; i %3C list.size() - 1; i++) %7B%0A                if (list.get(i)%5B1%5D %3E list.get(i + 1)%5B0%5D)
+return false;%0A                %7D else
  %7B%0A 
@@ -553,36 +553,45 @@
             
-return false
+end = intervals%5Bi%5D%5B1%5D
 ;%0A          

refactor 252