1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32
| class Solution { public int findMinArrowShots(int[][] points) { PriorityQueue<int[]> queue = new PriorityQueue<>(((o1, o2) -> { return Integer.compare(o1[0], o2[0]); }));
for(int[] point : points){ queue.offer(point); }
int[] arr = null; int count = 0; while (!queue.isEmpty()){ if (arr == null){ count ++; arr = queue.poll(); }else { int[] point = queue.poll(); if (arr[1] >= point[0]){ arr[0] = point[0]; arr[1] = Math.min(arr[1], point[1]); }else { count ++; arr = point; } } } return count; } }
|