1720.解码异或后的数组
链接:1720.解码异或后的数组
难度:Easy
标签:位运算、数组
简介:请解码返回原数组 arr 。可以证明答案存在并且是唯一的。
题解 1 - typescript
- 编辑时间:2021-05-06
 - 执行用时:144ms
 - 内存消耗:45.1MB
 - 编程语言:typescript
 - 解法介绍:利用异或读取下一个值。
 
function decode(encoded: number[], first: number): number[] {
  return [first, ...encoded.map(num => (first = num ^ first))];
}