Java 40ms Simple Solution


  • 0
    H
    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) {
        			 return a[1]-b[1];
        		}
        	});
        	int minArrows = 1;
        	int arrowPos = points[0][1];
        	for(int i=1;i<points.length;i++) {
        		int[] baloon = points[i];
        		if(baloon[0]>arrowPos) {
        			minArrows++;
        			arrowPos=baloon[1];
        		}
        	}
        	return minArrows;
        }
    }
    

Log in to reply
 

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