标签:style blog http java color os
题目:
Suppose a sorted array 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.
题解:
这道题是一道常见的二分查找法的变体题。
要解决这道题,需要明确rotated sorted array的特性,那么就是至少有一侧是排好序的(无论pivot在哪,自己画看看)。接下来就只需要按照这个特性继续写下去就好。以下就以伪代码方法来说明:
以上实现代码如下所示:
Reference:http://www.cnblogs.com/ider/archive/2012/04/01/binary_search.html
Search in Rotated Sorted Array leetcode java,布布扣,bubuko.com
Search in Rotated Sorted Array leetcode java
标签:style blog http java color os
原文地址:http://www.cnblogs.com/springfor/p/3858140.html