【算法练习】162. 寻找峰值
题目链接:162. 寻找峰值
看思路图:
class Solution {
public:
int findPeakElement(vector<int>& nums) {
int left = 0,right = nums.size()-1;
while(left<right)
{
int mid = left + (right-left)/2;
if(nums[mid]>nums[mid+1])
{
right = mid;
}
else if(nums[mid]<nums[mid+1])
{
left = mid+1;
}
}
return left;
}
};
原文地址:https://blog.csdn.net/2302_80652761/article/details/144360043
免责声明:本站文章内容转载自网络资源,如本站内容侵犯了原著者的合法权益,可联系本站删除。更多内容请关注自学内容网(zxcms.com)!