标签:int == 哈哈 min http amp pre 解决方案 解决
二分
一不小心耗时超过100%的c++解决方案。哈哈哈
class Solution {
public:
int findMin(vector<int>& nums) {
int l=0;
int r=nums.size()-1;
while(l<r)
{
int mid = (l+r)/2;
if(nums[mid]>=nums[l]&&nums[mid]<=nums[r])
{
if(nums[mid]==nums[r])
r=mid-1;
else
r=mid;
continue;
}
if(nums[mid]>=nums[l]&&nums[mid]>=nums[r])
{
if(nums[mid]==nums[l])
l=mid+1;
else
l=mid;
continue;
}
if(nums[mid]<=nums[l]&&nums[mid]>=nums[r])
{
if(nums[mid]==nums[l])
l=mid+1;
else
l=mid;
continue;
}
if(nums[mid]<=nums[l]&&nums[mid]<=nums[r])
{
if(nums[mid]==nums[r])
r=mid-1;
else
r=mid;
continue;
}
}
return nums[l];
}
};
LeetCode 153. Find Minimum in Rotated Sorted Array
标签:int == 哈哈 min http amp pre 解决方案 解决
原文地址:https://www.cnblogs.com/dacc123/p/10875172.html