class Solution { public: int search(vector<int>& nums, int target) { if(nums.size() == 0) return -1; int low = 0, high = nums.size()-1, mid; while(low+1 < high) { mid = (high - low)/2 + low; if(nums[mid] == target) return mid; if(nums[low] < nums[mid]) { if(nums[low] <= target && target <= nums[mid]) high = mid; else low = mid; } else{ if(nums[mid] <= target && target <= nums[high]) low = mid; else high = mid; } } if(nums[low] == target) return low; if(nums[high] == target) return high; return -1; } };