File tree 1 file changed +7
-6
lines changed
scripts/algorithms/S/Sum Game
1 file changed +7
-6
lines changed Original file line number Diff line number Diff line change
1
+ # Runtime: 173 ms (Top 90.14%) | Memory: 14.9 MB (Top 69.01%)
1
2
class Solution :
2
3
def sumGame (self , num : str ) -> bool :
3
4
n = len (num )
4
5
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`
6
7
if num [i ] == '?' :
7
8
q_cnt_1 += 1
8
- else :
9
+ else :
9
10
s1 += int (num [i ])
10
- q_cnt_2 = s2 = 0
11
+ q_cnt_2 = s2 = 0
11
12
for i in range (n // 2 , n ): # get digit sum and question mark count for the second half of `num`
12
13
if num [i ] == '?' :
13
14
q_cnt_2 += 1
14
- else :
15
+ else :
15
16
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
17
18
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
You can’t perform that action at this time.
0 commit comments