Skip to content

Commit 1a967c7

Browse files
authored
Create find-if-digit-game-can-be-won.cpp
1 parent dc0c24a commit 1a967c7

File tree

1 file changed

+18
-0
lines changed

1 file changed

+18
-0
lines changed

C++/find-if-digit-game-can-be-won.cpp

+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
// Time: O(n)
2+
// Space: O(1)
3+
4+
// brute force, game theory
5+
class Solution {
6+
public:
7+
bool canAliceWin(vector<int>& nums) {
8+
int total1 = 0, total2 = 0;
9+
for (const auto& x : nums) {
10+
if (x < 10) {
11+
total1 += x;
12+
} else {
13+
total2 += x;
14+
}
15+
}
16+
return total1 != total2;
17+
}
18+
};

0 commit comments

Comments
 (0)