mirror of
https://gitlab.com/mfocko/LeetCode.git
synced 2024-11-09 15:59:06 +01:00
rs: add «452. Minimum Number of Arrows to Burst Balloons»
Signed-off-by: Matej Focko <mfocko@redhat.com>
This commit is contained in:
parent
e9815ea0aa
commit
5e51f2ba08
1 changed files with 21 additions and 0 deletions
21
rs/minimum-number-of-arrows-to-burst-balloons.rs
Normal file
21
rs/minimum-number-of-arrows-to-burst-balloons.rs
Normal file
|
@ -0,0 +1,21 @@
|
|||
use std::cmp;
|
||||
|
||||
impl Solution {
|
||||
pub fn find_min_arrow_shots(mut points: Vec<Vec<i32>>) -> i32 {
|
||||
points.sort_unstable_by_key(|p| p[0]);
|
||||
|
||||
let mut used_arrows = 1;
|
||||
let mut max_x = points[0][1];
|
||||
|
||||
for point in points.iter().skip(1) {
|
||||
if point[0] <= max_x {
|
||||
max_x = cmp::min(max_x, point[1]);
|
||||
} else {
|
||||
used_arrows += 1;
|
||||
max_x = point[1];
|
||||
}
|
||||
}
|
||||
|
||||
used_arrows
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue