LeetCode 154. Find Minimum in Rotated Sorted Array II [Hard]

LeetCode 154. Find Minimum in Rotated Sorted Array II。

题目来源:https://leetcode.com/problems/find-minimum-in-rotated-sorted-array-ii

题目难度:Hard

本题和第 153 题可以使用同样的方法解决。

解答

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
class Solution {
public int findMin(int[] nums) {
if (nums.length == 0) {
return 0;
}

int min = nums[0];

for (int i = 1; i < nums.length; ++i) {
if (nums[i] < min) {
return nums[i];
}
}

return min;
}
}