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