left
to 0 and right
to the length of nums
minus 1.left
is less than or equal to right
:
mid
as the average of left
and right
(integer division).nums[mid]
is negative, set left
to mid + 1
.right
to mid - 1
.left
will be at the first non-negative number's index.left
.nums
minus left
.