# [LintCode/LeetCode] Find Minimum in Rotated Sorted Array I & II

## Problem

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.

## Notice

You may assume no duplicate exists in the array.

## Example

Given `[4, 5, 6, 7, 0, 1, 2]`

## Solution

``````public class Solution {
public int findMin(int[] num) {
int start = 0, end = num.length - 1;
while (start   1 < end) {
int mid = start   (end - start) / 2;
if (num[end] > num[mid]) end = mid;
else start = mid;
}
return num[start] < num[end] ? num[start] : num[end];
}
}
``````

## Problem

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.

The array may contain duplicates.

## Example

Given `[4,4,5,6,7,0,1,2]`

``````public class Solution {
public int findMin(int[] num) {
int min = Integer.MAX_VALUE;
for (int i = 0; i < num.length; i  ) {
min = Math.min(num[i], min);
}
return min;
}
}
``````