Java easy binary search


  • 0
    D
        public int findPeakElement(int[] nums) {
            return helper(nums,0,nums.length - 1);
        }
        public int helper(int[] nums, int low, int high) {
            if (low == high) return low;
            int mid = low + (high - low) / 2;
            if (nums[mid] > nums[mid + 1]) return helper(nums, low, mid);
            else return helper(nums,mid+1,high);
        }

Log in to reply
 

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