Source of the topic:
https://leetcode.com/problems/search-in-rotated-sorted-array/
Test Instructions Analysis:
Implements a lookup in a flipped array. (What is called the inverted array, that is, the original sequence of the array, select a point, the number of points before the point is placed behind the array, as 4,5,6,7,1,2,3 is a flip array).
Topic Ideas:
The idea of this topic is similar to that of binary search, and the difficulty is mainly in determining the position of two points.
Code (Python):
1 classsolution (object):2 defSearch (self, nums, target):3 """4 : Type Nums:list[int]5 : Type Target:int6 : Rtype:int7 """8Size =Len (nums)9First = 0;last =sizeTen whileFirst! =Last : OneMid = (first + last)//2 A ifNums[mid] = =Target: - returnMid - ifNums[first] <=Nums[mid]: the ifNums[first] <= Target andTarget <Nums[mid]: -Last =Mid - Else: -First = mid + 1 + Else: - ifNums[mid] < target andTarget <= nums[last-1]: +First = mid + 1 A Else: atLast =Mid - return-1
View Code
Reprint Please specify source: http://www.cnblogs.com/chruny/p/4918379.html
[Leetcode] (python): 033-search in rotated Sorted Array