Divisor Game — LeetCode 1025 Python Solution
EasyBrainteaserMathDynamic ProgrammingGame Theory
- Problem
- #1025
- Pattern
- Dynamic Programming
- Reading time
- 2 min
- Source
- leetcode.com
The problem
Alice and Bob take turns playing a game, with Alice starting first. Initially, there is a number n on the chalkboard.
Example
- Input
- n = 2
- Output
- true
- Explanation
- Alice chooses 1, and Bob has no more moves.
Python solution
Python
class Solution:
def divisorGame(self, n: int) -> bool:
return n % 2 == 0Complexity
| Measure | Complexity |
|---|---|
| Time | O(1) |
| Space | O(1) auxiliary |
Pattern: Dynamic Programming
Define a state, write the transition, and stop recomputing the same subproblem. LeetCode 1025. Divisor Game is filed here on both counts: the reference solution below belongs to the algorithm family this hub collects, and LeetCode tags it Dynamic Programming.
The dynamic programming guide has the Python template for the pattern and the 481 LeetCode problems that use it.
Related problems
Frequently asked questions
- How hard is LeetCode 1025. Divisor Game?
- LeetCode 1025. Divisor Game is rated Easy on LeetCode.
- What is the time complexity of LeetCode 1025. Divisor Game?
- The Python solution on this page runs in O(1).
- What is the space complexity of LeetCode 1025. Divisor Game?
- The Python solution on this page uses O(1) auxiliary space.
- What topics does LeetCode 1025. Divisor Game cover?
- LeetCode 1025. Divisor Game is tagged Brainteaser, Math, Dynamic Programming and Game Theory on LeetCode.