an easy understand java solution


  • 0
    H

    sort points with their start first and then compare it's end with the start of Balloons behind it

    public class Solution {
        public int findMinArrowShots(int[][] points) {
            int len =points.length;
            if(len==0)return 0;
    	Arrays.sort(points, new Comparator<int[]>() {
    		public int compare(int[] a, int[] b) {
         return a[0]-b[0];
    		}
    	});
    
        int res = 0;
       for(int i =0;i<len;i++){
            int[] cur = points[i];
            // System.out.print(cur[0]);
            while(i<len-1&&cur[1]>=points[i+1][0]){
                cur[0]=points[i+1][0];
                cur[1] = Math.min(cur[1],points[i+=1][1]);
            }
            res++;         
        }
        return res;
        }
    }
    

Log in to reply
 

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