Skip to content

Commit 13fbc65

Browse files
authored
Create find-if-digit-game-can-be-won.py
1 parent 1a967c7 commit 13fbc65

File tree

1 file changed

+29
-0
lines changed

1 file changed

+29
-0
lines changed
+29
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
# Time: O(n)
2+
# Space: O(1)
3+
4+
# brute force, game theory
5+
class Solution(object):
6+
def canAliceWin(self, nums):
7+
"""
8+
:type nums: List[int]
9+
:rtype: bool
10+
"""
11+
total1 = total2 = 0
12+
for x in nums:
13+
if x < 10:
14+
total1 += x
15+
else:
16+
total2 += x
17+
return total1 != total2
18+
19+
20+
# Time: O(n)
21+
# Space: O(1)
22+
# brute force, game theory
23+
class Solution2(object):
24+
def canAliceWin(self, nums):
25+
"""
26+
:type nums: List[int]
27+
:rtype: bool
28+
"""
29+
return sum(x for x in nums if x < 10) != sum(x for x in nums if x >= 10)

0 commit comments

Comments
 (0)