20241123 finished.
This commit is contained in:
parent
11e11afcd1
commit
ba46db892a
|
@ -332,3 +332,5 @@ mod p3244_shortest_distance_after_road_addition_queries_ii;
|
||||||
mod p3248_snake_in_matrix;
|
mod p3248_snake_in_matrix;
|
||||||
|
|
||||||
mod p3233_find_the_count_of_numbers_which_are_not_special;
|
mod p3233_find_the_count_of_numbers_which_are_not_special;
|
||||||
|
|
||||||
|
mod p3238_find_the_number_of_winning_players;
|
||||||
|
|
58
src/problem/p3238_find_the_number_of_winning_players.rs
Normal file
58
src/problem/p3238_find_the_number_of_winning_players.rs
Normal file
|
@ -0,0 +1,58 @@
|
||||||
|
/**
|
||||||
|
* [3238] Find the Number of Winning Players
|
||||||
|
*/
|
||||||
|
pub struct Solution {}
|
||||||
|
|
||||||
|
// submission codes start here
|
||||||
|
|
||||||
|
impl Solution {
|
||||||
|
pub fn winning_player_count(n: i32, pick: Vec<Vec<i32>>) -> i32 {
|
||||||
|
use std::collections::HashMap;
|
||||||
|
let n = n as usize;
|
||||||
|
|
||||||
|
let mut player = vec![HashMap::new(); n];
|
||||||
|
for p in pick {
|
||||||
|
let (p, b) = (p[0] as usize, p[1]);
|
||||||
|
|
||||||
|
let mut entry = player[p].entry(b).or_insert(0);
|
||||||
|
*entry += 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
player
|
||||||
|
.iter()
|
||||||
|
.enumerate()
|
||||||
|
.filter_map(|(i, map)| {
|
||||||
|
if map.iter().any(|(_, v)| *v > i) {
|
||||||
|
Some(())
|
||||||
|
} else {
|
||||||
|
None
|
||||||
|
}
|
||||||
|
})
|
||||||
|
.count() as i32
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// submission codes end
|
||||||
|
|
||||||
|
#[cfg(test)]
|
||||||
|
mod tests {
|
||||||
|
use super::*;
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn test_3238() {
|
||||||
|
assert_eq!(
|
||||||
|
2,
|
||||||
|
Solution::winning_player_count(
|
||||||
|
4,
|
||||||
|
vec![
|
||||||
|
vec![0, 0],
|
||||||
|
vec![1, 0],
|
||||||
|
vec![1, 0],
|
||||||
|
vec![2, 1],
|
||||||
|
vec![2, 1],
|
||||||
|
vec![2, 0]
|
||||||
|
]
|
||||||
|
)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user