Merge pull request #1991 from fwqaaq/patch-26

Update 0452.用最少数量的箭引爆气球.md rust 优化
This commit is contained in:
程序员Carl
2023-06-29 10:01:38 +08:00
committed by GitHub

View File

@ -290,26 +290,21 @@ int findMinArrowShots(int** points, int pointsSize, int* pointsColSize){
### Rust ### Rust
```Rust ```Rust
use std::cmp;
impl Solution { impl Solution {
pub fn find_min_arrow_shots(mut points: Vec<Vec<i32>>) -> i32 { pub fn find_min_arrow_shots(mut points: Vec<Vec<i32>>) -> i32 {
if points.is_empty() { if points.is_empty() {
return 0; return 0;
} }
points.sort_by_key(|point| point[0]); points.sort_by_key(|point| point[0]);
let mut result = 1;
let size = points.len(); for i in 1..points.len() {
let mut count = 1; if points[i][0] > points[i - 1][1] {
result += 1;
for i in 1..size {
if points[i][0] > points[i-1][1] {
count += 1;
} else { } else {
points[i][1] = cmp::min(points[i][1], points[i-1][1]); points[i][1] = points[i][1].min(points[i - 1][1])
} }
} }
result
return count;
} }
} }
``` ```