Golang | Leetcode Golang题解之第540题有序数组中的单一元素
题目:
题解:
func singleNonDuplicate(nums []int) int {
low, high := 0, len(nums)-1
for low < high {
mid := low + (high-low)/2
mid -= mid & 1
if nums[mid] == nums[mid+1] {
low = mid + 2
} else {
high = mid
}
}
return nums[low]
}