JS log(n) time solution


  • 0
    Y
    function findMin(numbers) {
      let lo = 0
      let hi = numbers.length - 1
      let min = Number.POSITIVE_INFINITY
      while (lo <= hi) {
        const mid = lo + Math.floor(0.5 * (hi - lo))
        min = Math.min(numbers[mid], min)
        if (numbers[mid] < numbers[hi]) {
          hi = mid - 1
        } else {
          lo = mid + 1
        }
      }
      return min
    }
    

Log in to reply
 

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