Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 496f80d

Browse files
Merge pull request youngyangyang04#1991 from fwqaaq/patch-26
Update 0452.用最少数量的箭引爆气球.md rust 优化
2 parents 1d47b74 + d1ccf8d commit 496f80d

File tree

1 file changed

+7
-12
lines changed

1 file changed

+7
-12
lines changed

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

Lines changed: 7 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -290,26 +290,21 @@ int findMinArrowShots(int** points, int pointsSize, int* pointsColSize){
290290
291291
### Rust
292292
```Rust
293-
use std::cmp;
294293
impl Solution {
295294
pub fn find_min_arrow_shots(mut points: Vec<Vec<i32>>) -> i32 {
296295
if points.is_empty() {
297296
return 0;
298297
}
299298
points.sort_by_key(|point| point[0]);
300-
301-
let size = points.len();
302-
let mut count = 1;
303-
304-
for i in 1..size {
305-
if points[i][0] > points[i-1][1] {
306-
count += 1;
307-
} else {
308-
points[i][1] = cmp::min(points[i][1], points[i-1][1]);
299+
let mut result = 1;
300+
for i in 1..points.len() {
301+
if points[i][0] > points[i - 1][1] {
302+
result += 1;
303+
} else {
304+
points[i][1] = points[i][1].min(points[i - 1][1])
309305
}
310306
}
311-
312-
return count;
307+
result
313308
}
314309
}
315310
```

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /