Decode XORed Array
给一个数组, 是or后的数组, 并且给了第一个数字, 求原文数组.
这个题看下真值表即可.
class Solution {
public int[] decode(int[] encoded, int first) {
int n = encoded.length;
int[] res = new int[n + 1];
int j = 0;
for(int i = 0; i <= n; i++){
res[i] = first;
if(j >= n)
break;
first ^= encoded[j++];
}
return res;
}
}