162. Find Peak Element

class Solution {
    public int findPeakElement(int[] nums) {
        for(int i=0;i<nums.length;i++)
            if((i==0||i>0&&nums[i]>nums[i-1])&&(i==nums.length-1||i<nums.length-1&&nums[i]>nums[i+1]))
                return i;
        return -1;
    }
}

  

posted @ 2017-10-24 01:20  Weiyu Wang  阅读(96)  评论(0编辑  收藏  举报