diff --git "a/problems/0452.\347\224\250\346\234\200\345\260\221\346\225\260\351\207\217\347\232\204\347\256\255\345\274\225\347\210\206\346\260\224\347\220\203.md" "b/problems/0452.\347\224\250\346\234\200\345\260\221\346\225\260\351\207\217\347\232\204\347\256\255\345\274\225\347\210\206\346\260\224\347\220\203.md" index 14456f92bf..898172bf5d 100644 --- "a/problems/0452.\347\224\250\346\234\200\345\260\221\346\225\260\351\207\217\347\232\204\347\256\255\345\274\225\347\210\206\346\260\224\347\220\203.md" +++ "b/problems/0452.\347\224\250\346\234\200\345\260\221\346\225\260\351\207\217\347\232\204\347\256\255\345\274\225\347\210\206\346\260\224\347\220\203.md" @@ -200,6 +200,29 @@ class Solution: # 不改变原数组 curr_min_right = min(curr_min_right, i[1]) return count ``` +```python +class Solution: # 不改变原数组,基于右侧坐标排序 + def findMinArrowShots(self, points: List[List[int]]) -> int: + # 题目说明points列表长度至少为1 + if len(points) == 1: + return 1 + + # 根据右侧坐标排序 + points.sort(key=lambda x: x[1]) + + # 初始化 + arrow = 0 + curr_min_right = float('-inf') + + # 根据右侧坐标排序后,更新curr_min_right时的point[1]自动保证为剩余气球中最小的 + # 右侧坐标值,节约else表达式中的判断步骤 + for point in points: + if point[0] > curr_min_right: + arrow += 1 + curr_min_right = point[1] + + return arrow +``` ### Go ```go func findMinArrowShots(points [][]int) int {