File tree 1 file changed +2
-26
lines changed
scripts/algorithms/D/Divisor Game
1 file changed +2
-26
lines changed Original file line number Diff line number Diff line change
1
+ // Runtime : 34 ms (Top 78.15 % ) | Memory : 16.60 MB (Top 64.13 % )
2
+
1
3
class Solution :
2
4
def divisorGame (self , n : int ) -> bool :
3
-
4
- """
5
- let's forget about Alice and Bob for a second and just concentrate on the n and plays
6
- if played optimally :
7
-
8
- 1 - player at 1 will loose since no factors
9
- 2 - player at 2 will win by choosing 1
10
- 3 - player at 3 will loose always since he/she has to choose 1. and then next player will always win because they are at 2
11
- 4 - player at 4 will win by choosing 1 as a factor as next player will have to play at 3
12
- 5 - player at 5 will loose because he has to choose 1, and player at 4 will always win
13
- 6 - player at 6 will always win by choosing 3 as a factor
14
- 7 - player at 7 will have to choose 1, and hence result 6 will make player at 6 to win
15
- 8 - player at 8 can choose 1 and win always
16
- .
17
- .
18
- .
19
- .
20
- Pattern detected
21
-
22
- Now, since Alice is the first player we can return bool values accordingly
23
-
24
-
25
- """
26
-
27
5
return n % 2 == 0
28
-
29
-
You can’t perform that action at this time.
0 commit comments