From cff523c993e88c7e8de553225af7112113ae6754 Mon Sep 17 00:00:00 2001 From: fw_qaq Date: Wed, 29 Mar 2023 19:58:07 +0800 Subject: [PATCH 1/2] =?UTF-8?q?Update=200452.=E7=94=A8=E6=9C=80=E5=B0=91?= =?UTF-8?q?=E6=95=B0=E9=87=8F=E7=9A=84=E7=AE=AD=E5=BC=95=E7=88=86=E6=B0=94?= =?UTF-8?q?=E7=90=83.md?= 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" | 22 ++++++------------- 1 file changed, 7 insertions(+), 15 deletions(-) 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 6b018f978a..3066d5292a 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" @@ -270,26 +270,18 @@ int findMinArrowShots(int** points, int pointsSize, int* pointsColSize){ ### Rust ```Rust -use std::cmp; impl Solution { pub fn find_min_arrow_shots(mut points: Vec>) -> i32 { - if points.is_empty() { - return 0; - } points.sort_by_key(|point| point[0]); - - let size = points.len(); - let mut count = 1; - - for i in 1..size { - if points[i][0] > points[i-1][1] { - count += 1; - } else { - points[i][1] = cmp::min(points[i][1], points[i-1][1]); + let mut result = 1; + for i in 1..points.len() { + if points[i][0] > points[i - 1][1] { + result += 1; + } else { + points[i][1] = points[i][1].min(points[i - 1][1]) } } - - return count; + result } } ``` From d1ccf8d3320eba0bfe0fb6dfdb88a4951c0729bb Mon Sep 17 00:00:00 2001 From: fw_qaq Date: Wed, 29 Mar 2023 20:00:07 +0800 Subject: [PATCH 2/2] =?UTF-8?q?Update=200452.=E7=94=A8=E6=9C=80=E5=B0=91?= =?UTF-8?q?=E6=95=B0=E9=87=8F=E7=9A=84=E7=AE=AD=E5=BC=95=E7=88=86=E6=B0=94?= =?UTF-8?q?=E7=90=83.md?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...256\255\345\274\225\347\210\206\346\260\224\347\220\203.md" | 3 +++ 1 file changed, 3 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 3066d5292a..79f9d59ad3 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" @@ -272,6 +272,9 @@ int findMinArrowShots(int** points, int pointsSize, int* pointsColSize){ ```Rust impl Solution { pub fn find_min_arrow_shots(mut points: Vec>) -> i32 { + if points.is_empty() { + return 0; + } points.sort_by_key(|point| point[0]); let mut result = 1; for i in 1..points.len() {