###### Algorithms—33.Search in Rotated Sorted Array

public class Solution {
public int search(int[] nums, int target) {
if (nums.length==1) {
if (nums[0]==target) {
return 0;
}else {
return -1;
}
}
int begin=0;
int end=nums.length-1;
int half=(end+begin)/2;
while (end-begin>1) {
int b=nums[begin];
int h=nums[half];
int e=nums[end];
if (h==target) {
return half;
}
if (b==target) {
return begin;
}
if (e==target) {
return end;
}
if (h>b) {
if (target>h) {
begin=half;
half=(end+begin)/2;
}else {
if (target>b) {
end=half;
half=(end+begin)/2;
}else {
begin=half;
half=(end+begin)/2;
}
}
}else {
if (target<h) {
end=half;
half=(end+begin)/2;
}else {
if (target>e) {
end=half;
half=(end+begin)/2;
}else {
begin=half;
half=(end+begin)/2;
}
}
}
}
if (nums[begin]==target) {
return begin;
}
if (nums[end]==target) {
return end;
}

return -1;
}
}

#### 【LEETCODE】33-Search in Rotated Sorted Array [Python]

2016-01-22 11:26:41

#### Search in Rotated Sorted Array -- LeetCode

2014-03-05 09:15:45

#### Search in Rotated Sorted Array II -- LeetCode

2014-03-06 02:04:55

#### 【LeetCode】Search in Rotated Sorted Array 解题报告

2014-10-25 17:00:36

#### Find Minimum in Rotated Sorted Array -- LeetCode

2014-10-25 07:11:17

#### LeetCode 33 — Search in Rotated Sorted Array（C++ Java Python）

2014-04-03 14:20:40

#### Find Minimum in Rotated Sorted Array II -- LeetCode

2014-10-25 07:12:45

#### [LeetCode]153.Find Minimum in Rotated Sorted Array

2015-01-31 17:21:26

#### leetcode 81. Search in Rotated Sorted Array II-旋转数组|二分查找

2016-06-07 11:34:23

#### [LeetCode]81.Search in Rotated Sorted Array II

2014-01-15 22:29:05

## 不良信息举报

Algorithms—33.Search in Rotated Sorted Array