算法---二分
作者:互联网
class Solution { public: int findPeakElement(vector<int>& nums) { // write code here //题目只需要求一个峰值即可,我门可以利用二分法+一直向峰值逼近的策略 int left =0; int right = nums.size()-1; while(left<right){ int mid = (left+right)>>1; if(nums[mid]<nums[mid+1]){ left = mid+1; } else{ right = mid; } } return right; } };
标签:二分,二分法,code,nums,int,峰值,---,算法,left 来源: https://www.cnblogs.com/jerry-autumn/p/16600350.html