Practice/Meta/Leetcode 74. Search a 2D Matrix
CodingMust
You are given an m x n integer matrix with the following special properties:
This means if you were to "flatten" the entire matrix into a single array by concatenating all rows, you would get one long sorted array.
Write a function that determines whether a given target value exists anywhere in this matrix. Your solution should take advantage of the sorted structure to achieve better than linear time complexity.
true if the target exists in the matrix, false otherwisem == matrix.length (number of rows)n == matrix[i].length (number of columns)1 <= m, n <= 100-10^4 <= matrix[i][j], target <= 10^4Example 1:
Input: matrix = [[1,3,5,7],[10,11,16,20],[23,30,34,60]], target = 3 Output: true Explanation: The value 3 is located in the first row at index 1
Example 2:
Input: matrix = [[1,3,5,7],[10,11,16,20],[23,30,34,60]], target = 13 Output: false Explanation: The value 13 does not exist in the matrix. It would fall between 11 and 16 if it were present
Example 3:
Input: matrix = [[1,3,5,7],[10,11,16,20],[23,30,34,60]], target = 60 Output: true Explanation: The value 60 is at the last position of the matrix