Simple Java Solution


  • 0
    H

    One test case (sorted by end):
    [[2,3],[4,5],[6,7],[2,7],[1,8],[8,12],[10,16]]
    ---^----^----^-----------------^---------- (4 arrows)

        public int findMinArrowShots(int[][] points) {
            if (points == null || points.length == 0) return 0;
            // sort by end
            Arrays.sort(points, (a, b) -> (a[1] - b[1]));
            int cnt = 1;
            int end = points[0][1];
            for (int i = 1; i < points.length; i++) {
                if (points[i][0] <= end) continue;
                cnt++;
                end = points[i][1];
            }
            return cnt;
        }
    

Log in to reply
 

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