start
to 0 and end
to len(nums) - 1
.start
is less than or equal to end
:
a. Calculate mid
as the midpoint between start
and end
.
b. If nums[mid]
equals target
, return true
.
c. If nums[start]
is less than nums[mid]
, the left half is sorted:
i. If target
is between nums[start]
and nums[mid]
, search the left half by setting end
to mid - 1
.
ii. Otherwise, search the right half by setting start
to mid + 1
.
d. If nums[start]
is greater than nums[mid]
, the right half is sorted:
i. If target
is between nums[mid]
and nums[end]
, search the right half by setting start
to mid + 1
.
ii. Otherwise, search the left half by setting end
to mid - 1
.
e. If nums[start]
, nums[mid]
, and nums[end]
are equal, we cannot determine the correct half, so we increment start
and decrement end
.false
.