```
public int singleNonDuplicate(int[] nums) {
int last = nums[0] - 1;
for (int i = 0; i < nums.length; i++) {
if (last != nums[i]) {
if ((i + 1) == nums.length || nums[i] != nums[i + 1]) return nums[i];
i++;
}
last = nums[i];
}
return last;
}
```