left
to 0 and right
to m * n - 1
.left
is less than or equal to right
:
a. Calculate mid
as the average of left
and right
(integer division).
b. Calculate the row index as mid // n
and the column index as mid % n
.
c. If the element at matrix[row][col]
is equal to target
, return true
.
d. If the element is less than target
, move left
to mid + 1
.
e. If the element is greater than target
, move right
to mid - 1
.target
is not found, return false
.