题目链接:
https://leetcode.cn/problems/find-if-digit-game-can-be-won/description/?envType=daily-question&envId=2024-11-30
题目描述:
解题思路:
将数组中小于10的元素相加求和得到sum1,大于等于10的元素相加求和得到sum2,如果sum1!=sum2则返回true,否则返回false
代码实现:
class Solution {
public:bool canAliceWin(vector<int>& nums) {int sum1 = 0;int sum2 = 0;for(int i=0; i<nums.size(); i++){if(nums[i]<10){sum1 += nums[i];}else{sum2+= nums[i];}}if(sum1 != sum2){return true;}return false;}
};