-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy path0081.cpp
More file actions
24 lines (22 loc) · 692 Bytes
/
Copy path0081.cpp
File metadata and controls
24 lines (22 loc) · 692 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
class Solution {
public:
bool search(const vector<int> &nums, int target) {
int left = 0, right = nums.size() - 1;
while (left <= right) {
int mid = left + (right - left) / 2;
if (nums[mid] == target) return true;
if (nums[mid] == nums[left]) {
left++;
continue;
}
bool pivotArr = nums[left] <= nums[mid];
bool targetArr = nums[left] <= target;
if ((pivotArr ^ targetArr) ? (pivotArr) : (nums[mid] < target)) {
left = mid + 1;
} else {
right = mid - 1;
}
}
return false;
}
};