3
bool search(vector<int> &nums, int target) {4
if (nums[0] == target or nums.back() == target) return true;5
// this line is redundant it reduces only the worst case when all elements8
const int n = nums.size();10
while (l + 1 < n and nums[l] == nums[l + 1]) l++;12
// if all elements are same14
if (nums[0] == target)20
// while last element is equal to 1st element21
while (h >= 0 and nums[h] == nums[0]) h--;22
int start = l, end = h;24
// find the point of pivot ie from where the rotation starts27
int mid = l + (h - l) / 2;28
if (nums[mid] >= nums[0])38
h = end; // if no pivot exits then search space is from start -e end40
if (target > nums[end])41
l = start, h = pivot - 1; // search space second half43
l = pivot, h = end; // search space first half46
// normal binary search48
int mid = l + (h - l) / 2;49
if (nums[mid] > target)51
else if (nums[mid] < target)