forked from fishercoder1534/Leetcode
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path_452.java
31 lines (28 loc) · 1.03 KB
/
_452.java
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
package com.fishercoder.solutions;
import java.util.Arrays;
public class _452 {
public static class Solution1 {
/**
* credit: https://discuss.leetcode.com/topic/66579/java-greedy-soution/6
*/
public int findMinArrowShots(int[][] points) {
if (points == null || points.length == 0) {
return 0;
}
// sort points based on their end point.
Arrays.sort(points, (p1, p2) -> Integer.compare(p1[1], p2[1]));
int currentEnd = points[0][1];
int count = 1;
for (int[] p : points) {
// if the point starts after currentEnd, it means this balloons not been bursted. Then we shot the balloon in its end point. Otherwise, means this balloon has been bursted, then ignore it.
if (p[0] > currentEnd) {
count++;
currentEnd = p[1];
} else {
continue;
}
}
return count;
}
}
}