Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
class Solution {
public:
int search(vector<int>& nums, int target) {
int lo = 0, hi = nums.size() - 1;
while(lo <= hi){
int m = (lo + hi)/2;
int mid = nums[m];
//We need to check whether mid and target are within the same sub array
if(((nums[m] < nums[0]) == (target < nums[0])))
mid = nums[m];
else
mid = target < nums[0] ? INT_MIN:INT_MAX;
if(mid < target)
lo = m + 1;
else if(mid > target)
hi = m - 1;
else
return m;
}
return -1;
}
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment