left
and right
, to the start and end of the array respectively.left
is less than right
.mid
index as the average of left
and right
.mid
is not the last element and nums[mid]
is less than nums[mid + 1]
, move the left
pointer to mid + 1
(ascending slope).right
pointer to mid
(descending slope or peak).left
equals right
, the search space is narrowed down to one element, which is the peak. Return left
.