Java simple solution


  • 0
    A
        public int findMinArrowShots(int[][] points) {
            if (points.length == 0)
                return 0;
            Arrays.sort(points, new Comparator<int[]>() {
                @Override
                public int compare(int[] entry1, int[] entry2) {
                    return entry1[0] - entry2[0];
                }
            });
            int min = points[0][0];
            int max = points[0][1];
            int count = 1;
            for (int i = 1; i < points.length; i++) {
                int start = points[i][0];
                int end = points[i][1];
                if (start >= min && start <= max) {
                    min = Math.max(min, start);
                    max = Math.min(max, end);
                } else {
                    count++;
                    min = start;
                    max = end;
                }
            }
            return count;
        }
    

Log in to reply
 

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