题目
package cast_01;
import java.util.Arrays;
import java.util.Comparator;
public class T4 {
public static void main(String[] args) {
int[][] points = { { 10, 16 }, { 2, 8 }, { 1, 6 }, { 7, 12 } };
System.out.println(findMinArrowShots(points));
}
public static int findMinArrowShots(int[][] points) {
if (points.length == 0) {
return 0;
}
Arrays.sort(points, new Comparator<int[]>() {
@Override
public int compare(int[] o1, int[] o2) {
if (o1[1] > o2[1]) {
return 1;
} else if (o1[1] < o2[1]) {
return -1;
} else {
return 0;
}
}
});
for (int[] arr : points) {
for (int x : arr) {
System.out.print(x + " ");
}
System.out.println();
}
int res = 1;
int pos = points[0][1];
for (int[] arr : points) {
if (arr[0] > pos) {
pos = arr[1];
res++;
}
}
return res;
}
}