2 lines binary search Ruby


  • 0
    def find_peak_element(nums)
      n = nums.size - 1
      (0..n).bsearch { |i| i == n || nums[i] > nums[i+1] }
    end
    

    Could be one line, but I don't like code duplication.


Log in to reply
 

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