Use that XOR of 2 similar elements is 0 (c^c=0). So, after XORing all the elements which repeat twice , and then XOR the result with the unique element to get the answer.

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