33. Search in Rotated Sorted Array
文章目录
**Description**Hints**Submissions**Solutions
Total Accepted: 168414 Total Submissions: 524192 Difficulty: Medium Contributor: LeetCode
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.
Hide Company Tags LinkedIn Bloomberg Uber Facebook Microsoft Hide Tags Binary Search Array Hide Similar Problems (M) Search in Rotated Sorted Array II (M) Find Minimum in Rotated Sorted Array
** 解题思路 **
Use Binary Search
The idea is that when rotating the array, there must be one half of the array that is still in sorted order.
For example, 6 7 1 2 3 4 5, the order is disrupted from the point between 7 and 1. So when doing binary search, we can make a judgement that which part is ordered and whether the target is in that range, if yes, continue the search in that half, if not continue in the other half.
|
|
文章作者 Hustbill
上次更新 2017-06-10