From 3d36ecc092325ce614404d5cc1b69337153d1187 Mon Sep 17 00:00:00 2001 From: YiChih Wang Date: Thu, 13 Jan 2022 21:55:14 +0800 Subject: [PATCH] =?UTF-8?q?0452.=E7=94=A8=E6=9C=80=E5=B0=91=E6=95=B0?= =?UTF-8?q?=E9=87=8F=E7=9A=84=E7=AE=AD=E5=BC=95=E7=88=86=E6=B0=94=E7=90=83?= =?UTF-8?q?=20Rust=20=E8=AA=9E=E8=A8=80=E5=AF=A6=E7=8F=BE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../0452.用最少数量的箭引爆气球.md | 25 +++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/problems/0452.用最少数量的箭引爆气球.md b/problems/0452.用最少数量的箭引爆气球.md index ebfe648f..33bbad55 100644 --- a/problems/0452.用最少数量的箭引爆气球.md +++ b/problems/0452.用最少数量的箭引爆气球.md @@ -239,5 +239,30 @@ 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]); + } + } + + return count; + } +} +``` -----------------------