Skip to content

Commit 3d36ecc

Browse files
committed
0452.用最少数量的箭引爆气球 Rust 語言實現
1 parent 6b85bbd commit 3d36ecc

File tree

1 file changed

+25
-0
lines changed

1 file changed

+25
-0
lines changed

problems/0452.用最少数量的箭引爆气球.md

+25
Original file line numberDiff line numberDiff line change
@@ -239,5 +239,30 @@ int findMinArrowShots(int** points, int pointsSize, int* pointsColSize){
239239
}
240240
```
241241
242+
### Rust
243+
```Rust
244+
use std::cmp;
245+
impl Solution {
246+
pub fn find_min_arrow_shots(mut points: Vec<Vec<i32>>) -> i32 {
247+
if points.is_empty() {
248+
return 0;
249+
}
250+
points.sort_by_key(|point| point[0]);
251+
252+
let size = points.len();
253+
let mut count = 1;
254+
255+
for i in 1..size {
256+
if points[i][0] > points[i-1][1] {
257+
count += 1;
258+
} else {
259+
points[i][1] = cmp::min(points[i][1], points[i-1][1]);
260+
}
261+
}
262+
263+
return count;
264+
}
265+
}
266+
```
242267
-----------------------
243268
<div align="center"><img src=https://code-thinking.cdn.bcebos.com/pics/01二维码一.jpg width=500> </img></div>

0 commit comments

Comments
 (0)