20241008 finished.
This commit is contained in:
parent
d1610560ff
commit
368dab3616
463
Cargo.lock
generated
463
Cargo.lock
generated
File diff suppressed because it is too large
Load Diff
|
@ -257,3 +257,4 @@ mod p1928_minimum_cost_to_reach_destination_in_time;
|
|||
mod p1227_airplane_seat_assignment_probability;
|
||||
mod p2187_minimum_time_to_complete_trips;
|
||||
mod p871_minimum_number_of_refueling_stops;
|
||||
mod p1436_destination_city;
|
36
src/problem/p1436_destination_city.rs
Normal file
36
src/problem/p1436_destination_city.rs
Normal 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")]));
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user