LC 0540 [M] Single Element in a Sorted Array - ALawliet/algorithms GitHub Wiki
first binary search with modified m and l
class Solution:
def singleNonDuplicate(self, nums: List[int]) -> int:
l, r = 0, len(nums) - 1
while l < r:
m = (l + r) // 2
if m % 2 == 1:
m -= 1 # should be at even index
if nums[m] == nums[m+1]:
l = m + 2 # yes pair, single must be on right, +1 to skip dupe
else:
r = m # no pair, single must be on left
return nums[l]