Awesome java python solution


  • 0
    F
        public int findMinArrowShots(int[][] points) {
            if (points == null || points.length == 0) {
                return 0;
            }
            Arrays.sort(points, (o1, o2) -> Integer.compare(o1[1], o2[1]));
            int result = 1;
            int end = points[0][1];
            for (int i = 1; i < points.length; i++) {
                if (points[i][0] > end) {
                    result++;
                    end = points[i][1];
                }
            }
            return result;
        }
    

    python

        def findMinArrowShots(self, points):
            points = sorted(points, key=lambda x: x[1])
            res, end = 0, float('-inf')
            for point in points:
                if point[0] > end:
                    end = point[1]
                    res += 1
            return res
    

Log in to reply
 

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