Very straight forward solution:

Just count how many 1 should appear on each bit from 1 to n

and count again how many actually appears

set the bit with extra 1s to 1 and return the result
===============^^====================
Short explanation:
Say you happen to have 1 to n plus x, then you have extra 1 and extra 0 at places that x has 1 and 0.
If you have more than two x, then for each additional x you have to delete any number from 1 to n and add an x, which will only add to the number of 1s, if not remain unchanged, in the place that have extra 1s.
In this case I scan each element once for each bit. Since there are at most 64 bits or 32 bits I consider it a O(n) solution. I improved it a little with scanning only the number of bits needed.
int findDuplicate(vector<int>& nums) {
int result = 0, count,bit,i;
for(bit = 1; bit >0 && bit < nums.size(); bit <<= 1 )
{
count = 0;
for(i = 0;i<nums.size();i++) count += bool(nums[i]&bit)  bool(i&bit);
if(count > 0) result = bit;
}
return result;
}