Java solution using Greedy


  • 1
    S
    public class Solution {
        public int findMinArrowShots(int[][] points) {
            if(points==null || points.length==0 || points[0].length==0) return 0;
    	   Arrays.sort(points, new Comparator<int[]>() {
    		   public int compare(int[] a, int[] b) {
    			if(a[1]==b[1]) return a[0]-b[0];
    			else return a[1]-b[1];
    		}
    	});
    	int pre_end = points[0][1];
    	int num = 1;
    	for( int i = 1; i < points.length; i++){
    	    if(points[i][0] > pre_end){
    	        num++;
    	        pre_end = points[i][1];
    	    }
    	}
    	return num;
        }
    }
    

Log in to reply
 

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