Skip to content

Commit

Permalink
Merge pull request youngyangyang04#1991 from fwqaaq/patch-26
Browse files Browse the repository at this point in the history
Update 0452.用最少数量的箭引爆气球.md rust 优化
  • Loading branch information
youngyangyang04 authored Jun 29, 2023
2 parents 1d47b74 + d1ccf8d commit 496f80d
Showing 1 changed file with 7 additions and 12 deletions.
19 changes: 7 additions & 12 deletions problems/0452.用最少数量的箭引爆气球.md
Original file line number Diff line number Diff line change
Expand Up @@ -290,26 +290,21 @@ int findMinArrowShots(int** points, int pointsSize, int* pointsColSize){
### Rust
```Rust
use std::cmp;
impl Solution {
pub fn find_min_arrow_shots(mut points: Vec<Vec<i32>>) -> 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
}
}
```
Expand Down

0 comments on commit 496f80d

Please sign in to comment.