-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsolution11_2.java
More file actions
37 lines (34 loc) · 787 Bytes
/
Copy pathsolution11_2.java
File metadata and controls
37 lines (34 loc) · 787 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
34
35
36
37
package nowcoder;
public class solution11_2 {
public int minNumberInRotateArray(int[] nums) {
if(nums.length == 0)
{
return 0;
}
int l=0,h = nums.length-1;
while(l<h)
{
int m = l+(h-l)/2;
if(nums[l]==nums[m]&&nums[m]==nums[h])
{
return minNumer(nums,l,h);
}else if(nums[m]<=nums[h])
{
h= m;
}else{
l = m+1;
}
}
return nums[l];
}
private int minNumer(int[] nums, int l, int h) {
for(int i = l;i<h;i++)
{
if(nums[i] > nums[i+1])
{
return nums[i+1];
}
}
return nums[l];
}
}