292. Nim Game
All prompts are owned by LeetCode. To view the prompt, click the title link above.
First completed : May 23, 2024
Last updated : July 04, 2024
Related Topics : Math, Brainteaser, Game Theory
Acceptance Rate : 57.27 %
Notes 1 - true 2 - true 3 - true 4 - false 5 - true -1, any, -3 6 - true -2, any, -3 7 - true -3, any, -3 8 - false As long as you're not a multiple of 4, you can force the other into becoming the multiple of 4, thus winning it for yourself. Basically just intuitive proof by mathematical induction.
class Solution:
def canWinNim(self, n: int) -> bool:
return not 0 == n % 4