Simply find the first index whose "partner index" (the index xor 1) holds a different value.

**Ruby:**

```
def single_non_duplicate(nums)
nums[(0..nums.size).bsearch { |i| nums[i] != nums[i^1] }]
end
```

**Python**

```
def singleNonDuplicate(self, nums):
lo, hi = 0, len(nums) - 1
while lo < hi:
mid = (lo + hi) / 2
if nums[mid] == nums[mid ^ 1]:
lo = mid + 1
else:
hi = mid
return nums[lo]
```

**Java:**

```
public int singleNonDuplicate(int[] nums) {
int lo = 0, hi = nums.length - 1;
while (lo < hi) {
int mid = (lo + hi) >>> 1;
if (nums[mid] == nums[mid ^ 1])
lo = mid + 1;
else
hi = mid;
}
return nums[lo];
}
```