810. Chalkboard XOR Game
Read the full problem statement on LeetCode.
Difficulty: hard Acceptance: 63% Topics: Array, Math, Bit Manipulation, Brainteaser, Game Theory
View full problem on LeetCode Reading material
Reference solution (spoiler · python)
# Time: O(n)
# Space: O(1)
from operator import xor
from functools import reduce
class Solution(object):
def xorGame(self, nums):
"""
:type nums: List[int]
:rtype: bool
"""
return reduce(xor, nums) == 0 or \
len(nums) % 2 == 0
Solution from kamyu104/LeetCode-Solutions · MIT