C++ | Leetcode C++题解之第540题有序数组中的单一元素
题目:
题解:
class Solution {
public:int singleNonDuplicate(vector<int>& nums) {int low = 0, high = nums.size() - 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];}
};