An even starting value always moves to an odd one, while every legal move from an odd value reaches an even one; therefore the first player wins exactly for even n.
Complexity
O(1) time and O(1) space.
Determine whether the first player can force a win in the divisor subtraction game.
An even starting value always moves to an odd one, while every legal move from an odd value reaches an even one; therefore the first player wins exactly for even n.
O(1) time and O(1) space.
package main
func divisorGame(n int) bool { return n%2 == 0 }
class Solution:
def divisorGame(self, n: int) -> bool:
return n % 2 == 0
function divisorGame(n: number): boolean {
return n % 2 === 0;
}