题目:
思路:
注意:
[[-2147483646,-2147483645],[2147483646,2147483647]]
Integer.compare()
Java实现:
class Solution {
public int findMinArrowShots(int[][] points) {
// 贪心 ,即求不重叠的区间个数!
// 先排序
Arrays.sort(points,new Comparator<int[]>(){
@Override
public int compare(int[] a,int[] b){
return Integer.compare(a[1],b[1]);
}
});
// 筛选出不重叠的
int x_end=points[0][1];
int count=1;
for(int i=1;i<points.length;i++){
int start=points[i][0];
if(start > x_end){
count++;
x_end=points[i][1];
}
}
return count;
}
}