My simple AC java solution


  • 0
    Y
    public class Solution {
    public int findPeakElement(int[] num) {
        int len =0;
        for(int i=0; i<num.length; i++){
            if(num[len]>=num[i]){
                continue;
            }
            if(num[len]<num[i]){
                len=i;
            }
        }
        return len;
    }
    

    }


  • 0
    L
     int findPeakElement(const vector<int> &num) {
        int size = num.size();
        if(size<=1)
          return 0;
        for(int i=0;i<size-1;i++)
        {
            if(num[i]>num[i+1])
            {
               return i;
            }
        }
        return size-1;
        
    }

Log in to reply
 

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.