20241023 finished.
This commit is contained in:
parent
1cfe77f777
commit
3102da99a8
|
@ -272,3 +272,4 @@ mod p3192_minimum_operations_to_make_binary_array_elements_equal_to_one_ii;
|
|||
mod p908_smallest_range_i;
|
||||
mod p910_smallest_range_ii;
|
||||
mod p3184_count_pairs_that_form_a_complete_day_i;
|
||||
mod p3185_count_pairs_that_form_a_complete_day_ii;
|
40
src/problem/p3185_count_pairs_that_form_a_complete_day_ii.rs
Normal file
40
src/problem/p3185_count_pairs_that_form_a_complete_day_ii.rs
Normal file
|
@ -0,0 +1,40 @@
|
|||
/**
|
||||
* [3185] Count Pairs That Form a Complete Day II
|
||||
*/
|
||||
pub struct Solution {}
|
||||
|
||||
|
||||
// submission codes start here
|
||||
|
||||
impl Solution {
|
||||
pub fn count_complete_day_pairs(hours: Vec<i32>) -> i64 {
|
||||
use std::collections::HashMap;
|
||||
|
||||
let mut map = HashMap::new();
|
||||
let mut result = 0;
|
||||
|
||||
for hour in hours {
|
||||
let hour = hour % 24;
|
||||
if let Some(&c) = map.get(&((24 - hour) % 24)) {
|
||||
result += c;
|
||||
}
|
||||
let entry = map.entry(hour).or_insert(0);
|
||||
*entry += 1;
|
||||
}
|
||||
|
||||
result
|
||||
}
|
||||
}
|
||||
|
||||
// submission codes end
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
|
||||
#[test]
|
||||
fn test_3185() {
|
||||
assert_eq!(2, Solution::count_complete_day_pairs(vec![12, 12, 30, 24, 24]));
|
||||
assert_eq!(3, Solution::count_complete_day_pairs(vec![72, 48, 24, 3]));
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user