leetcode 33. Search in Rotated Sorted Array (无重复数的旋转数组找定值)

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.

思路:找规律。。。二分。。。

观察发现。。。a[mid]<a[r]的时候,后半段有序;

a[mid]>a[r]的时候,前半段有序。。

然后根据有序区间的端点值,确定tar是在该有序区间,还是在另一半区间。

 

 

说点什么

您将是第一位评论人!

提醒
wpDiscuz