Skip to content

Commit

Permalink
73: Re-submit
Browse files Browse the repository at this point in the history
  • Loading branch information
sankichi92 committed Jan 1, 2024
1 parent 0e52257 commit caa4285
Showing 1 changed file with 22 additions and 6 deletions.
28 changes: 22 additions & 6 deletions 73-minimum-number-of-arrows-to-burst-balloons/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
pub fn find_min_arrow_shots(mut points: Vec<Vec<i32>>) -> i32 {
points.sort_unstable();
points.sort_unstable_by_key(|point| point[0]);

let mut arrows = 1;
let mut current_end = points[0][1];

for point in points.iter().skip(1) {
if point[0] <= current_end {
continue;
if point[0] <= current_end {
current_end = current_end.min(point[1]);
} else {
arrows += 1;
current_end = point[1];
}

arrows += 1;
current_end = point[1];
}

arrows
Expand Down Expand Up @@ -43,4 +43,20 @@ mod tests {
2
)
}

#[test]
fn failed_case1() {
assert_eq!(
find_min_arrow_shots(vec![
vec![9, 12],
vec![1, 10],
vec![4, 11],
vec![8, 12],
vec![3, 9],
vec![6, 9],
vec![6, 7]
]),
2
)
}
}

0 comments on commit caa4285

Please sign in to comment.