Back to DSA
Search a 2D Matrix
easyYou are given an m-by-n matrix of integers where each row is sorted in ascending order and the first value of each row exceeds the last value of the row above it. Given a target integer, determine whether it exists in the matrix. Your solution should run in O(log(m*n)) time.
Examples
Example 1:
Input:
matrix = [[1,4,7],[10,13,16],[19,22,25]], target = 13Output:
trueExplanation: 13 appears in the second row.
Example 2:
Input:
matrix = [[1,4,7],[10,13,16],[19,22,25]], target = 14Output:
falseExplanation: 14 is not present in the matrix.
Hints
1234567