Skip to content

Commit 1b6d99f

Browse files
committed
[leet] findMinArrowShots
1 parent 1fadbbd commit 1b6d99f

File tree

1 file changed

+18
-0
lines changed

1 file changed

+18
-0
lines changed
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
var findMinArrowShots = function (points) {
2+
if (!points || points.length === 0) return 0;
3+
4+
points.sort((a, b) => (a[1] === b[1] ? a[0] - b[0] : a[1] - b[1]));
5+
6+
let arrows = 1;
7+
let end = points[0][1];
8+
9+
for (let i = 1; i < points.length; i++) {
10+
const [start, e] = points[i];
11+
if (start > end) {
12+
arrows++;
13+
end = e;
14+
}
15+
}
16+
17+
return arrows;
18+
};

0 commit comments

Comments
 (0)