```
class Solution(object):
def singleNonDuplicate(self, nums):
"""
:type nums: List[int]
:rtype: int
"""
if not nums: return 0
i, j = 0, len(nums)-1
while i < j:
mid = (i+j)/2
if (mid-i) % 2 == 0:
if nums[mid] == nums[mid-1]:
j = mid-2
else:
if nums[mid] != nums[mid+1]: return nums[mid]
i = mid+2
else:
if nums[mid] == nums[mid-1]:
i = mid+1
else:
j = mid-1
return nums[j]
```