This is actually Activity selection problem


  • 0
    2

    https://en.wikipedia.org/wiki/Activity_selection_problem

    public class Solution {
        public int findMinArrowShots(int[][] points) {
            Arrays.sort(points, new C());
            long last = Long.MIN_VALUE;
            int count = 0;
            for (int i = 0; i < points.length; i++) {
                if (last < points[i][0]) {
                    last = points[i][1];
                    count++;
                }
            }
            return count;
        }
        
        class C implements Comparator<int[]> {
            public int compare(int[] a1, int[] a2) {
                return Integer.compare(a1[1], a2[1]);
            }
        }
    }
    

Log in to reply
 

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