본문 바로가기
코딩 문제

[LeetCode] 1720 Decode XORred Array

by Zach Choi 2023. 1. 29.
728x90
반응형

Solution

  • Use principle : A ^ B = C -> A ^ C = B
class Solution {
public:
    vector<int> decode(vector<int>& encoded, int first) {
        vector<int> res;

        res.push_back(first);

        for (int i = 0; i != encoded.size(); ++i)
        {
            res.push_back(res.back() ^ encoded[i]);
        }

        return res;
    }
};

 

 

728x90
반응형