public int findMin(int[] num) {
int s = 0;
int e = num.length-1;
int m;
while(s<e){
m = (s+e)/2;
if(num[m]>=num[s] && num[s] > num[e])
s = m+1;
else
e = m;
}
return num[s];
}网上一个大牛的解法,就是如果中间比两边大了,就往右走。不然转点在前面Find Minimum in Rotated Sorted Array - Leetcode (Java)
最新推荐文章于 2022-07-27 13:01:15 发布
本文介绍了一种高效查找旋转排序数组中最小元素的方法。通过对比数组中间元素与两端元素大小来决定搜索范围,最终实现O(log n)的时间复杂度。
363

被折叠的 条评论
为什么被折叠?



