mirror of
https://github.com/youngyangyang04/leetcode-master.git
synced 2025-07-08 00:43:04 +08:00
Merge pull request #1020 from andywang0607/master
0452.用最少数量的箭引爆气球 Rust 語言實現
This commit is contained in:
@ -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<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]);
|
||||
}
|
||||
}
|
||||
|
||||
return count;
|
||||
}
|
||||
}
|
||||
```
|
||||
-----------------------
|
||||
<div align="center"><img src=https://code-thinking.cdn.bcebos.com/pics/01二维码一.jpg width=500> </img></div>
|
||||
|
Reference in New Issue
Block a user