20241130 finished.

This commit is contained in:
jackfiled 2024-11-30 11:31:00 +08:00
parent 9238af57e8
commit b256588a78
2 changed files with 32 additions and 0 deletions

View File

@ -342,3 +342,5 @@ mod p3206_alternating_groups_i;
mod p3208_alternating_groups_ii; mod p3208_alternating_groups_ii;
mod p3250_find_the_count_of_monotonic_pairs_i; mod p3250_find_the_count_of_monotonic_pairs_i;
mod p3232_find_if_digit_game_can_be_won;

View File

@ -0,0 +1,30 @@
/**
* [3232] Find if Digit Game Can Be Won
*/
pub struct Solution {}
// submission codes start here
impl Solution {
pub fn can_alice_win(nums: Vec<i32>) -> bool {
nums.into_iter()
.map(|x| if x >= 10 { (0, x) } else { (x, 0) })
.fold([(0, 0)], |acc, e| [(acc[0].0 + e.0, acc[0].1 + e.1)])
.iter()
.all(|x| x.0 != x.1)
}
}
// submission codes end
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn test_3232() {
assert!(!Solution::can_alice_win(vec![1, 2, 3, 4, 10]));
assert!(Solution::can_alice_win(vec![1, 2, 3, 4, 5, 14]));
assert!(Solution::can_alice_win(vec![5, 5, 5, 25]));
}
}