Java Easy Solution


  • 0
    W

    Basic idea is sorting the double array first, then check the conclusion of balloons from ascending order. If the new balloon's start is larger than the smallest end of the previous ones, count one arrow and start counting new one from current balloon.

    '''
    public class Solution {
    public int findMinArrowShots(int[][] points) {
    if(points.length==0){
    return 0;
    }
    Comparator<int[]> c=new Comparator<int[]>(){
    public int compare(int[] a, int[] b){
    if(a[0]==b[0]) return a[1]-b[1];
    else return a[0]-b[0];
    }
    };
    int count=1;
    Arrays.sort(points,c);
    int minend = points[0][1];
    for(int i=1;i<points.length;i++){
    int[] cur = points[i];
    if(cur[0]>minend){
    count++;
    minend=cur[1];
    }
    else minend=Math.min(minend,cur[1]);
    }
    return count;
    }
    }

    '''


Log in to reply
 

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