برنامه نویسی

حداقل تعداد فلش برای ترکیدن بالن

Summarize this content to 400 words in Persian Lang
مشکل

class Solution {
public int findMinArrowShots(int[][] points) {
//remove all the overlapping baloons
//this will lead to only baloons that are not overlapping
//and we will need at min that many arros to burst them

//step1 : sort the give points in ascending order of Xend
Arrays.sort(points,(a,b)-> Integer.compare(a[1],b[1]));
//step2: get the count of non overlapping intervals and that will the no. of arrows we will need
int xstart = points[0][0];
int xend = points[0][1];
int count =1;// atleast one arrow is needed to burst baloon(s)
for(int i =1;i<points.length;i++){
if(xend < points[i][0]){// xend is less than than the xstart of next baloon hence they are not overlapping
count++;
xend = points[i][1]; //update xend
}
}
return count;
}
}

وارد حالت تمام صفحه شوید

از حالت تمام صفحه خارج شوید

مشکل

class Solution {
    public int findMinArrowShots(int[][] points) {
        //remove all the overlapping baloons 
        //this will lead to only baloons that are not overlapping
        //and we will need at min that many arros to burst them


        //step1 : sort the give points in ascending order of Xend
        Arrays.sort(points,(a,b)-> Integer.compare(a[1],b[1]));
        //step2: get the count of non overlapping intervals and that will the no. of arrows we will need
        int xstart = points[0][0];
        int xend = points[0][1];
        int count =1;// atleast one arrow is needed to burst baloon(s)
        for(int i =1;i<points.length;i++){
            if(xend < points[i][0]){// xend is less than than the xstart of next baloon hence they are not overlapping
                count++;
                xend = points[i][1]; //update xend
            }
        }
        return count;
    }
}
وارد حالت تمام صفحه شوید

از حالت تمام صفحه خارج شوید

نوشته های مشابه

دیدگاهتان را بنویسید

نشانی ایمیل شما منتشر نخواهد شد. بخش‌های موردنیاز علامت‌گذاری شده‌اند *

دکمه بازگشت به بالا