public int findMin(int[] num) {
int l = 0, h = num.length-1, m;
while(l < h)
{
while(l < h && num[l] == num[l+1])
{
l++;
}
while(l < h && num[h] == num[h-1])
{
h--;
}
if(l == h)
{
return num[l];
}
m = (l+h)/2;
if(num[l] < num[h])
{
return num[l];
}
else if(num[m] >= num[h])
{
l = m+1;
}
else //num[m]<num[h]
{
h = m;
}
}
return num[l];
}
[leetcode] Find Minimum in Rotated Sorted Array II
最新推荐文章于 2024-06-04 23:11:16 发布