[
math
game
]
Leetcode 0292 Nim Game
Problem statement
https://leetcode.com/problems/nim-game/
Solution
Just check number of stones modulo 4
: for every 1
we can answer 3
, for 2
we can answer 2
and for 3
we can answer 1
.
Complexity
Time and space complexity is O(1)
Code
class Solution:
def canWinNim(self, n):
return n%4 != 0