452 greedy

This commit is contained in:
mhrooz 2024-06-16 10:38:56 +02:00
parent 3a982c9b0c
commit 321b2a8668

18
452-240616-pass/main.py Normal file
View File

@ -0,0 +1,18 @@
class Solution:
def findMinArrowShots(self, points: list[list[int]]) -> int:
def rule(l):
return (l[0], l[1])
sorted_points = sorted(points, key=rule)
rlt = 0
end = -inf
for point in sorted_points:
st = point[0]
ed = point[1]
if st > end:
rlt += 1
end = ed
else:
end = min(end, ed)
return rlt
sol = Solution()
print(sol.findMinArrowShots([[10, 16],[2, 8],[1, 6], [7, 12]]))