Could there be an O(log n) Java solution cleaner than this :) ?


  • 0
    E
    public class Solution {
        public int findPeakElement(int[] nums) {
            int lower = 0;
            int upper = nums.length;
            while (upper - lower > 1) {
                int mid = lower + upper >> 1;
                if (nums[mid] < nums[mid - 1])
                    upper = mid;
                else
                    lower = mid;
            }
            return lower;
        }
    }

Log in to reply
 

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