my two ways java solutions


  • 0
     public int findMinArrowShots(int[][] points) {
            if(points == null || points.length < 1) return 0;
            Arrays.sort(points, (a,b) -> a[0] == b[0] ? a[1] -b[1] :a[0] - b[0]);
            int ret = 1;
            int end = points[0][1];
            for(int i = 1; i < points.length; i++){
                if(end >= points[i][0]){
                     end = Math.min(end, points[i][1]);
                }else{
                    ret++;
                    end = points[i][1];
                }
            }
            return ret;
     
        
        /*
            if(points == null || points.length < 1){
                return 0;
            }
            int sum = points.length;
            Arrays.sort(points, (a,b)->{if(a[0] == b[0]) return a[1] - b[1];
                                         else return a[0] - b[0];});
            int count = 1;
            int start = points[0][1];
            for(int i = 1; i < points.length; i++){
                if(points[i][0] <= start){
                   sum--;
                    start = Math.min(start, points[i][1]);
                }else{
                    start = points[i][1];
                }
            }
            return sum;
        */}
    

Log in to reply
 

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.