Java super simple solution


  • 0
    public class Solution {
        public int findPeakElement(int[] nums) {
            int end = nums.length - 1;
            int start = 0;
            int mid, mid1;
            while (start + 1 < end) {
                mid = start + (end - start) / 2;
                mid1 = mid + 1;
                if (nums[mid] > nums[mid1]) {
                    end = mid;
                } else {
                    start = mid1;
                }
            }
            return nums[start] > nums[end] ? start : end;
        }
    }

Log in to reply
 

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