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 mid = (lo + hi)/2;
if(target == nums[mid])
return mid;
if(nums[lo] <= nums[mid]){
if(target < nums[mid] && target >= nums[lo])
hi = mid - 1;
else
lo = mid + 1;
}
else{
if(target > nums[mid] && target <= nums[hi])
lo = mid + 1;
else
hi = mid - 1;
}
}
return -1;
}
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment