int search(vector<int>& nums, int target) {
if (nums.size() == 0)
return -1;
int l = 0, r = nums.size() - 1;
//二分法找出旋转点
while (l < r) {
int mid = (l + r) / 2;
if (nums[mid] > nums[l])
l = mid;
else
r = mid;
}
int split = l;
if (target <= nums[split] && target >= nums[0])
{
r = split;
l = 0;
while (l < r) {
int mid = (l + r) / 2;
if (nums[mid] < target)
l = mid + 1;
else
r = mid;
}
if (nums[l] == target)
return l;
else
return -1;
}
else
{
r = nums.size() - 1;
l = split + 1;
while (l < r) {
int mid = (l + r) / 2;
if (nums[mid] < target)
l = mid + 1;
else
r = mid;
}
if (l<nums.size() && nums[l] == target)
return l;
else
return -1;
}
}