FindMinimumInRotatedSortedArrayII

problem

  1. Find Minimum in Rotated Sorted Array II

Hard

Suppose an array sorted in ascending order 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 1:

1
2
>Input: [1,3,5]
>Output: 1

Example 2:

1
2
>Input: [2,2,2,0,1]
>Output: 0

Note:

key

???

solution

1
2
3
4
5
6
7
8
9
10
class Solution {
public int findMin(int[] nums) {
for (int i = 0; i < nums.length - 1; i++) {
if (nums[i] > nums[i + 1]) {
return nums[i + 1];
}
}
return nums[0];
}
}

perfect