```
int search(int* nums, int numsSize, int target) {
int left, right, mid;
left = 0;
right = numsSize-1;
if (right<left)
return -1;
while ( left<=right) {
mid = (left+right)/2;
if (target == nums[mid])
return mid;
if(nums[mid]>=nums[left]){
if(target >= nums[left] && target < nums[mid])
right = mid-1;
else
left = mid+1;
}
else {
if(target <= nums[right] && target > nums[mid]) {
left = mid + 1;
} else
right = mid-1;
}
}
return -1;
}
```