Skip to content

Commit bbdbd25

Browse files
committed
Divisor Game
1 parent 8278bf2 commit bbdbd25

File tree

1 file changed

+26
-0
lines changed

1 file changed

+26
-0
lines changed

1025-divisor-game.py

+26
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
"""
2+
Problem Link: https://leetcode.com/problems/divisor-game/
3+
4+
Alice and Bob take turns playing a game, with Alice starting first.
5+
Initially, there is a number N on the chalkboard. On each player's turn, that player makes a move consisting of:
6+
Choosing any x with 0 < x < N and N % x == 0.
7+
Replacing the number N on the chalkboard with N - x.
8+
Also, if a player cannot make a move, they lose the game.
9+
Return True if and only if Alice wins the game, assuming both players play optimally.
10+
11+
Example 1:
12+
Input: 2
13+
Output: true
14+
Explanation: Alice chooses 1, and Bob has no more moves.
15+
16+
Example 2:
17+
Input: 3
18+
Output: false
19+
Explanation: Alice chooses 1, Bob chooses 1, and Alice has no more moves.
20+
21+
Note:
22+
1 <= N <= 1000
23+
"""
24+
class Solution:
25+
def divisorGame(self, N: int) -> bool:
26+
return N % 2 == 0

0 commit comments

Comments
 (0)