810. Chalkboard XOR Game ¶ Time: $O(n)$ Space: $O(1)$ C++JavaPython 1 2 3 4 5 6 7class Solution { public: bool xorGame(vector<int>& nums) { const int xors = accumulate(nums.begin(), nums.end(), 0, bit_xor<int>()); return xors == 0 || nums.size() % 2 == 0; } }; 1 2 3 4 5 6class Solution { public boolean xorGame(int[] nums) { final int xors = Arrays.stream(nums).reduce((a, b) -> a ^ b).getAsInt(); return xors == 0 || nums.length % 2 == 0; } } 1 2 3class Solution: def xorGame(self, nums: list[int]) -> bool: return functools.reduce(operator.xor, nums) == 0 or len(nums) % 2 == 0