#3232
Easy Algorithms Find if digit game can be won
Array Math
81.5% acceptance
Feb 25, 2026
196
12
You are given an array of positive integers nums.
Alice and Bob are playing a game. In the game, Alice can choose either all single-digit numbers
or all double-digit numbers from nums, and the rest of the numbers are given to Bob.
Alice wins if the sum of her numbers is strictly greater than the sum of Bob's numbers.
Return true if Alice can win this game, otherwise, return false.
Solution
Rust
Time O(n)
Space O(1)
impl Solution {
pub fn can_alice_win(nums: Vec<i32>) -> bool {
let single: i32 = nums.iter().filter(|&&x| x < 10).sum();
let double: i32 = nums.iter().filter(|&&x| x >= 10).sum();
single != double
}
}