leetcode 33[medium]---Search in Rotated Sorted Array

难度:medium

Suppose an array sorted in ascending order is rotated at some pivot unknown to you beforehand.

(i.e., 0 1 2 4 5 6 7 might become 4 5 6 7 0 1 2).

You are given a target value to search. If found in the array return its index, otherwise return -1.

You may assume no duplicate exists in the array.


思路:假设有一个排序的按未知的旋转轴旋转的数组(比如,0 1 2 4 5 6 7 可能成为4 5 6 7 0 1 2)。给定一个目标值进行搜索,如果在数组中找到目标值返回数组中的索引位置,否则返回-1。

           如果用遍历序列的方法,或者双支针的方法从头尾双向查找都会超时。显然需用两分法缩小查找范围,然后双支针查找。


leetcode 33[medium]---Search in Rotated Sorted Array