Skip to content

Commit 0d6ffa9

Browse files
committed
Runtime: 173 ms (Top 90.14%) | Memory: 14.9 MB (Top 69.01%)
1 parent f470e9f commit 0d6ffa9

File tree

1 file changed

+7
-6
lines changed

1 file changed

+7
-6
lines changed
+7-6
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,19 @@
1+
# Runtime: 173 ms (Top 90.14%) | Memory: 14.9 MB (Top 69.01%)
12
class Solution:
23
def sumGame(self, num: str) -> bool:
34
n = len(num)
45
q_cnt_1 = s1 = 0
5-
for i in range(n//2): # get digit sum and question mark count for the first half of `num`
6+
for i in range(n//2): # get digit sum and question mark count for the first half of `num`
67
if num[i] == '?':
78
q_cnt_1 += 1
8-
else:
9+
else:
910
s1 += int(num[i])
10-
q_cnt_2 = s2 = 0
11+
q_cnt_2 = s2 = 0
1112
for i in range(n//2, n): # get digit sum and question mark count for the second half of `num`
1213
if num[i] == '?':
1314
q_cnt_2 += 1
14-
else:
15+
else:
1516
s2 += int(num[i])
16-
s_diff = s1 - s2 # calculate sum difference and question mark difference
17+
s_diff = s1 - s2 # calculate sum difference and question mark difference
1718
q_diff = q_cnt_2 - q_cnt_1
18-
return not (q_diff % 2 == 0 and q_diff // 2 * 9 == s_diff) # When Bob can't win, Alice wins
19+
return not (q_diff % 2 == 0 and q_diff // 2 * 9 == s_diff) # When Bob can't win, Alice wins

0 commit comments

Comments
 (0)