leetcode33. 搜索旋转排序数组

leetcode33. 搜索旋转排序数组_第1张图片
搜索旋转排序数组
#python3
class Solution:
    def search(self, nums, target):
        """
        :type nums: List[int]
        :type target: int
        :rtype: int
        """
        left = 0
        right =  len(nums)-1

        # 先找到最小数的位置
        # 左大右小
        while leftnums[right]: left=mid+1
            else:right=mid
        root = right  # 此时right = left

        left = 0
        right =  len(nums)-1
        while left<=right:
            mid = (left+right)//2
            realmid = (mid+root)%len(nums)
            if nums[realmid]==target:return realmid
            if nums[realmid]

你可能感兴趣的:(leetcode33. 搜索旋转排序数组)