1486. XOR Operation in an Array ¶ Time: $O(n)$ Space: $O(1)$ C++JavaPython 1 2 3 4 5 6 7 8 9class Solution { public: int xorOperation(int n, int start) { int ans = 0; for (int i = 0; i < n; ++i) ans ^= start + 2 * i; return ans; } }; 1 2 3 4 5 6 7 8class Solution { public int xorOperation(int n, int start) { int ans = 0; for (int i = 0; i < n; ++i) ans ^= start + 2 * i; return ans; } } 1 2 3 4class Solution: def xorOperation(self, n: int, start: int) -> int: return functools.reduce(operator.xor, [start + 2 * i for i in range(n)])