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

https://leetcode.com/problems/find-minimum-in-rotated-sorted-array/

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).

Find the minimum element.

You may assume no duplicate exists in the array.

public int FindMin(int[] nums)
{
int start = 0, end = nums.Length - 1, mid;
if (end == 0)
return nums[0];
while (start+1!=end)
{
if (nums[start] < nums[end])
return nums[start];
mid = (start + end) / 2;
if (nums[start] < nums[mid])
start = mid;
else
end = mid;
}
return Math.Min(nums[start], nums[end]);
}

int findMin(vector<int>& nums)
{
int l = 0, r = nums.size() - 1, mid;
while (l < r)
{
if (nums[l] < nums[r])
break;
mid = l + (r - l) / 2;
if (nums[mid] >= nums[l])
l = mid + 1;
else
r = mid;
}
return nums[l];
}

int helper(vector<int> &nums, int l, int r)
{
int res = nums[l];
for (int i = l + 1; i <= r; i++)
res = min(res, nums[i]);
return res;
}

int findMin(vector<int> nums)
{
int l = 0, r = nums.size() - 1, mid;
while (l < r)
{
if (nums[l] < nums[r])
break;
mid = l + (r - l) / 2;

if (nums[l] == nums[mid] && nums[r] == nums[mid])//如果三个值相等 只能顺序查找
return helper(nums, l, r);

if (nums[mid] >= nums[l])
l = mid + 1;
else
r = mid;
}
return nums[l];
}

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

2014-10-25 07:11:17

#### 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

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

2015-03-19 19:03:14

#### leetcode 153: Find Minimum in Rotated Sorted Array

2014-12-30 04:30:30

#### LeetCode(154) Find Minimum in Rotated Sorted Array II

2015-01-21 09:10:48

#### LeetCode(153)Find Minimum in Rotated Sorted Array

2015-01-21 06:04:50

#### LeetCode 154. Find Minimum in Rotated Sorted Array II（旋转数组查找）

2016-05-26 00:57:56

#### 【LeetCode-面试算法经典-Java实现】【153-Find Minimum in Rotated Sorted Array（找旋转数组中的最小数字）】

2015-08-21 06:24:18

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

2014-03-05 09:15:45

## 不良信息举报

LeetCode-153.Find Minimum in Rotated Sorted Array