Open chencl1986 opened 1 year ago
原题链接: https://leetcode.cn/problems/xor-operation-in-an-array/
解题思路:
start
nums[i] = start + 2 * i
/** * @param {number} n * @param {number} start * @return {number} */ var xorOperation = function (n, start) { let result = start // 初始值为start for (let i = 1; i < n; i++) { // 根据题意,逐个进行异或运算 result ^= start + 2 * i } return result }
原题链接: https://leetcode.cn/problems/xor-operation-in-an-array/
解题思路:
start
,按照nums[i] = start + 2 * i
依次进行异或运算即可。