-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSolution.java
More file actions
33 lines (29 loc) · 926 Bytes
/
Copy pathSolution.java
File metadata and controls
33 lines (29 loc) · 926 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
public class Solution {
public int findMin(int[] nums) {
if (nums == null || nums.length == 0)
return Integer.MIN_VALUE;
int numsLen = nums.length;
int left = 0;
int right = numsLen - 1;
if (nums[left] == nums[right]) {
int minValue = nums[0];
for (int i = 1; i < numsLen; i++) {
if (nums[i] < minValue)
minValue = nums[i];
}
return minValue;
} else if (nums[left] < nums[right]) {
return nums[left];
} else {
while (left + 1 < right) {
int mid = (left + right) >> 1;
if (nums[mid] >= nums[left]) {
left = mid;
} else {
right = mid;
}
}
return nums[right];
}
}
}