Skip to content

Commit 804aa37

Browse files
refactor 452
1 parent 22f3385 commit 804aa37

File tree

1 file changed

+21
-19
lines changed
  • src/main/java/com/fishercoder/solutions

1 file changed

+21
-19
lines changed

src/main/java/com/fishercoder/solutions/_452.java

Lines changed: 21 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -29,26 +29,28 @@
2929
*/
3030
public class _452 {
3131

32-
//credit: https://discuss.leetcode.com/topic/66579/java-greedy-soution/6
33-
public int findMinArrowShots(int[][] points) {
34-
35-
if (points == null || points.length == 0) {
36-
return 0;
37-
}
38-
// sort points based on their end point.
39-
Arrays.sort(points, (p1, p2) -> Integer.compare(p1[1], p2[1]));
40-
int currentEnd = points[0][1];
41-
int count = 1;
42-
for (int[] p : points) {
43-
// 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.
44-
if (p[0] > currentEnd) {
45-
count++;
46-
currentEnd = p[1];
47-
} else {
48-
continue;
32+
public static class Solution1 {
33+
/**
34+
* credit: https://discuss.leetcode.com/topic/66579/java-greedy-soution/6
35+
*/
36+
public int findMinArrowShots(int[][] points) {
37+
if (points == null || points.length == 0) {
38+
return 0;
4939
}
40+
// sort points based on their end point.
41+
Arrays.sort(points, (p1, p2) -> Integer.compare(p1[1], p2[1]));
42+
int currentEnd = points[0][1];
43+
int count = 1;
44+
for (int[] p : points) {
45+
// 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.
46+
if (p[0] > currentEnd) {
47+
count++;
48+
currentEnd = p[1];
49+
} else {
50+
continue;
51+
}
52+
}
53+
return count;
5054
}
51-
return count;
5255
}
53-
5456
}

0 commit comments

Comments
 (0)