-
星空
class Solution(object): def findMinArrowShots(self, points): """ :type points: List[List[int]] :rtype: int """ ans = 0 emin = MAXINT = 0x7FFFFFFF for s, e in sorted(points): if emin < s: ans += 1 emin = MAXINT emin = min(emin, e) return ans + bool(points)
-
星空
class Solution { public int findMinArrowShots(int[][] points) { if (points.length == 0) { return 0; } Arrays.sort(points, (a, b) -> a[1] - b[1]); int arrowPos = points[0][1]; int arrowCnt = 1; for (int i = 1; i < points.length; i++) { if (arrowPos >= points[i][0]) { continue; } arrowCnt++; arrowPos = points[i][1]; } return arrowCnt; } }
-
星空
class Solution(object): def findMinArrowShots(self, points): """ :type points: List[List[int]] :rtype: int """ points = sorted(points, key = lambda x: x[1]) res, end = 0, -float('inf') for interval in points: if interval[0] > end: res += 1 end = interval[1] return res
-