diff --git a/src/problem/mod.rs b/src/problem/mod.rs index 164079f..2ba5ca3 100644 --- a/src/problem/mod.rs +++ b/src/problem/mod.rs @@ -129,4 +129,5 @@ mod p242_valid_anagram; mod p49_group_anagrams; mod p202_happy_number; mod p219_contains_duplicate_ii; -mod p128_longest_consecutive_sequence; \ No newline at end of file +mod p128_longest_consecutive_sequence; +mod p452_minimum_number_of_arrows_to_burst_balloons; \ No newline at end of file diff --git a/src/problem/p452_minimum_number_of_arrows_to_burst_balloons.rs b/src/problem/p452_minimum_number_of_arrows_to_burst_balloons.rs new file mode 100644 index 0000000..edf4460 --- /dev/null +++ b/src/problem/p452_minimum_number_of_arrows_to_burst_balloons.rs @@ -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>) -> 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() { + } +}