class Solution {
public:
int findPeakElement(vector<int>& nums) {
    int i=0;
    int n=nums.size();
    while(i<n){
    if(i==0){   //处理第一位
       if(nums[1] < nums[0])
       return 0;
       else {
        i++;
        continue;
       }
    }
           if(i==n-1){  //处理最后一位
      if(nums[i-1] < nums[i])
      return i;
      else{
      i++;
      continue;
         }
    }
    if((nums[i-1]<nums[i])&&(nums[i]>nums[i+1]))
      return i;
    i++;
    }
return 0;           //处理只有一个元素的情况。。。注意。。。
  }
};

相关文章:

  • 2021-08-12
  • 2021-04-12
  • 2022-12-23
  • 2022-12-23
  • 2021-11-11
  • 2022-12-23
  • 2021-07-09
猜你喜欢
  • 2022-12-23
  • 2021-07-24
  • 2022-12-23
  • 2021-07-02
  • 2021-12-15
  • 2022-01-09
  • 2021-10-02
相关资源
相似解决方案