leetcode

Solution to some Leetcode problems written in C++
git clone git://git.dimitrijedobrota.com/leetcode.git
Log | Files | Refs | README | LICENSE

0540.cpp (426B)


0 class Solution {
1 public:
2 int singleNonDuplicate(vector<int> &nums) {
3 int low = 0, high = nums.size() - 1;
4 while (low < high) {
5 int mid = low + (high - low) / 2;
6 if ((mid % 2 == 0 && nums[mid] == nums[mid + 1]) || (mid % 2 == 1 && nums[mid] == nums[mid - 1]))
7 low = mid + 1;
8 else
9 high = mid;
10 }
11 return nums[low];
12 }
13 };