Given an integer n
and an integer start
.
Define an array nums
where nums[i] = start + 2*i
(0-indexed) and n == nums.length
.
Return the bitwise XOR of all elements of nums
.
1 <= n <= 1000
0 <= start <= 1000
n == nums.length
一次异或就行
class Solution(object): def xorOperation(self, n, start): """ :type n: int :type start: int :rtype: int """ ans = 0 for i in range(n): ans ^= (start + i * 2) return ans