The grid matrix has m rows and n columns, and its values read in order when you go row by row: each row is sorted from smallest to largest, and every row starts with a value bigger than the last value of the row above it. Return true if target is one of the values in matrix, and false if it is not.
Aim for O(log(m · n)) time.
27 is larger than every value in the first two rows and smaller than 40, so it can only be in the third row, and it is.
20 would fall between 19 (the end of the second row) and 22 (the start of the third), and no cell holds it.
A single row is just a sorted list, and a value may appear more than once.
Constraints
m == matrix.lengthn == matrix[i].length1 <= m, n <= 100-10⁴ <= matrix[i][j], target <= 10⁴Because each row starts above where the previous one ended, reading the grid row by row gives one sorted list of m · n values.
true