题解 | #寻找峰值#
class Solution { public: /** * 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可 * * * @param nums int整型vector * @return int整型 */ int findPeakElement(vector<int>& nums) { // write code here nums.push_back(INT_MIN); int left=0; int right=nums.size()-1; int mid=0; int lastmid=-1; while(left<=right){ mid=left+right; mid/=2; if(nums[mid]>nums[mid+1]){ //- right=mid-1; lastmid=mid; } else{ //+ left=mid+1; } } return lastmid; } };