452 greedy
This commit is contained in:
		
							
								
								
									
										18
									
								
								452-240616-pass/main.py
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										18
									
								
								452-240616-pass/main.py
									
									
									
									
									
										Normal 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]])) | ||||||
		Reference in New Issue
	
	Block a user