[LeetCode] Find if Digit Game Can Be Won

3232. Find if Digit Game Can Be Won

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.

1
2
3
4
5
6
7
8
9
10
11
class Solution {
public:
bool canAliceWin(vector<int>& nums) {
int sum1 = 0, sum = 0;
for(auto& n : nums) {
sum += n;
if(n < 10) sum1 += n;
}
return sum != sum1 * 2;
}
};
Author: Song Hayoung
Link: https://songhayoung.github.io/2024/07/28/PS/LeetCode/find-if-digit-game-can-be-won/
Copyright Notice: All articles in this blog are licensed under CC BY-NC-SA 4.0 unless stating additionally.