var decode = function(encoded, first) { let len = encoded.length; let newArr = new Array(len+1); newArr[0] = first; for(let i=1;i<len+1;i++){ newArr[i] = newArr[i-1]^encoded[i-1]; } return newArr; };
// 示例 1:
// 输入:encoded = [1,2,3], first = 1 // 输出:[1,0,2,1] // 解释:若 arr = [1,0,2,1] ,那么 first = 1 且 encoded = [1 XOR 0, 0 XOR 2, 2 XOR 1] = [1,2,3] // 示例 2: // 输入:encoded = [6,2,7,3], first = 4 // 输出:[4,2,0,7,4] // 提示: // 2 <= n <= 104 // encoded.length == n - 1 // 0 <= encoded[i] <= 105 // 0 <= first <= 105