26. Search a 2D Matrix

Each row of matrix is sorted, and the first value of every row is greater than the last value of the row above. Return whether target exists, in O(log(m·n)).

Example 1

Input: matrix = [[1,4,7],[10,13,16],[20,22,25]], target = 13
Output: true

Example 2

Input: matrix = [[1,4,7],[10,13,16],[20,22,25]], target = 15
Output: false
Hint 1

Reading the rows one after another gives a single sorted array of length m·n.

Hint 2

Index k maps to row k / n, column k % n.

Binary SearchMatrix