clueless coding // TODO: be smarter

LeetCode Missing Number: CPP Solution



TL;DR Code Solution


int missingNumber(vector<int>& nums) {

    int xorx = 0;
    for (int i = 0; i < nums.size(); i++) {
        xorx ^= i;
        xorx ^= nums[i];
    }
    return xorx ^ (nums.size());

}