```
public class Solution {
public int SingleNumber(int[] nums) {
if (nums.Length == 0)
return 0;
if (nums.Length == 1)
return nums[0];
HashSet<int> hs = new HashSet<int>();
for (int i = 0; i < nums.Length; i++)
{
if (!(hs.Add(nums[i])))
hs.Remove(nums[i]);
}
return hs.First();
}
}
```