20241008 finished.

This commit is contained in:
jackfiled 2024-10-09 13:30:49 +08:00
parent d1610560ff
commit 368dab3616
3 changed files with 291 additions and 211 deletions

463
Cargo.lock generated

File diff suppressed because it is too large Load Diff

View File

@ -257,3 +257,4 @@ mod p1928_minimum_cost_to_reach_destination_in_time;
mod p1227_airplane_seat_assignment_probability; mod p1227_airplane_seat_assignment_probability;
mod p2187_minimum_time_to_complete_trips; mod p2187_minimum_time_to_complete_trips;
mod p871_minimum_number_of_refueling_stops; mod p871_minimum_number_of_refueling_stops;
mod p1436_destination_city;

View File

@ -0,0 +1,36 @@
/**
* [1436] Destination City
*/
pub struct Solution {}
// submission codes start here
impl Solution {
pub fn dest_city(paths: Vec<Vec<String>>) -> String {
use std::collections::HashMap;
let mut out_map = HashMap::new();
for path in paths.iter() {
let start_entry = out_map.entry(&path[0]).or_insert(0);
*start_entry += 1;
out_map.entry(&path[1]).or_insert(0);
}
out_map.iter().filter(|(_, &v)| v == 0).map(|(k, _)| k.to_string()).next().unwrap()
}
}
// submission codes end
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn test_1436() {
assert_eq!("A".to_owned(), Solution::dest_city(vec![vec_string!("B", "C"), vec_string!("D", "B"), vec_string!("C", "A")]));
}
}