【每日一题】1720. 解码异或后的数组

https://leetcode-cn.com/problems/decode-xored-array/

/*
异或的逆运算还是异或
*/
class Solution {
    public int[] decode(int[] encoded, int first) {
        int[] res = new int[encoded.length + 1];
        res[0] = first;

        for(int i = 0; i < encoded.length; i++){
            res[i + 1] = res[i] ^ encoded[i];
        }
        
        return res;
    }
}
posted @ 2021-05-06 20:05  zjy4fun  阅读(43)  评论(0编辑  收藏  举报