20240516 Finished

This commit is contained in:
jackfiled 2024-05-16 10:29:00 +08:00
parent b6a9384603
commit 2c204daf5a
2 changed files with 46 additions and 1 deletions

View File

@ -130,3 +130,4 @@ mod p49_group_anagrams;
mod p202_happy_number; mod p202_happy_number;
mod p219_contains_duplicate_ii; mod p219_contains_duplicate_ii;
mod p128_longest_consecutive_sequence; mod p128_longest_consecutive_sequence;
mod p452_minimum_number_of_arrows_to_burst_balloons;

View File

@ -0,0 +1,44 @@
/**
* [452] Minimum Number of Arrows to Burst Balloons
*/
pub struct Solution {}
// submission codes start here
impl Solution {
pub fn find_min_arrow_shots(points: Vec<Vec<i32>>) -> i32 {
if points.is_empty() {
return 0;
}
let mut points : Vec<(i32, i32)> = points.iter().map(|p|{(p[0], p[1])}).collect();
points.sort_unstable_by(|a, b| {
a.1.cmp(&b.1)
});
let mut result = 0;
let mut pos = points[0].1;
for point in points {
if point.0 > pos {
pos = point.1;
result += 1;
}
}
result + 1
}
}
// submission codes end
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn test_452() {
}
}