> For the complete documentation index, see [llms.txt](https://blog.yushunchen.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://blog.yushunchen.com/algo/binary-search/find-minimum-in-rotated-sorted-array.md).

# Find Minimum in Rotated Sorted Array

{% embed url="<https://www.lintcode.com/problem/159/>" %}

## Solution 1 (Java)

```java
public class Solution {
    /**
     * @param nums: a rotated sorted array
     * @return: the minimum number in the array
     */
    public int findMin(int[] nums) {
        if (nums == null || nums.length == 0) {
            return -1;
        }
        int left = 0, right = nums.length - 1;
        int target = nums[nums.length - 1];

        while (left + 1 < right) {
            int mid = left + (right - left) / 2;
            if (nums[mid] >= target) {
                left = mid;
            } else {
                right = mid;
            }
        }

        return Math.min(nums[left], nums[right]);
    }
}
```

### Notes

* We use the last element as the target since we lack a target for the binary search. The reason is that we can reduce the range that contains the minimum number using this target.&#x20;
* Also, note that the array may not be rotated at all.&#x20;
