传统滑动窗口可以解决问题,看代码
O(nlogn)
class Solution:
def findMinArrowShots(self, points: List[List[int]]) -> int:
points.sort()
low = 0
high = 0
count = 0
if (points):
low = points[0][0]
high = points[0][1]
else:
return 0
for point in points:
if (point[0] > high):
count += 1
low = point[0]
high = point[1]
elif (point[1] < high and point[0] > low):
high = point[1]
return count+1