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; } };
标签:二分,nums,int,---,算法,left From: https://www.cnblogs.com/jerry-autumn/p/16600350.html