From a864252a196d3c12e28217a94063ca5ebf2a412e Mon Sep 17 00:00:00 2001 From: Shengchao Wang Date: Mon, 10 Feb 2025 14:19:27 -0500 Subject: [PATCH] =?UTF-8?q?=E5=A2=9E=E5=8A=A00452.=E7=94=A8=E6=9C=80?= =?UTF-8?q?=E5=B0=91=E6=95=B0=E9=87=8F=E7=9A=84=E7=AE=AD=E5=BC=95=E7=88=86?= =?UTF-8?q?=E6=B0=94=E7=90=83=EF=BC=8Cpython=EF=BC=8C=E5=9F=BA=E4=BA=8E?= =?UTF-8?q?=E5=8F=B3=E4=BE=A7=E5=9D=90=E6=A0=87=E6=8E=92=E5=BA=8F=E7=9A=84?= =?UTF-8?q?=E7=AE=97=E6=B3=95=EF=BC=8C=E8=8A=82=E7=BA=A6=E8=A1=A8=E8=BE=BE?= =?UTF-8?q?=E5=BC=8F=E4=B8=AD=E7=9A=84=E5=88=A4=E6=96=AD=E6=AD=A5=E9=AA=A4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...25\347\210\206\346\260\224\347\220\203.md" | 23 +++++++++++++++++++ 1 file changed, 23 insertions(+) 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 {