LeetCode 33 Search in Rotated Sorted Array

题目

c++

二分

class Solution {
public:
    int search(vector& nums, int target) {
        
        if(nums.size()==0)
            return -1;
        int start=0;
        int end = nums.size()-1;
        
        int ans=-1;
        while(start=nums[start]&&nums[start] nums[mid])
            {
                if(target>=nums[start]&&nums[start]>nums[mid])
                {
                    end = mid-1;
                }
                else if(target>=nums[end]&&nums[end]

你可能感兴趣的:(LeetCode 33 Search in Rotated Sorted Array)