Search a 2D Matrix

You are given an m x n integer matrix with each row sorted in non-decreasing order and the first integer of each row greater than the last integer of the previous row. You need to determine if a given target integer is present in the matrix. The solution must operate with a time complexity of O(log(m * n)).

Constraints

  • m == matrix.length
  • n == matrix[i].length
  • 1 <= m, n <= 100
  • -10^4 <= matrix[i][j], target <= 10^4
Saving… · 2 lines
class Solution:
def search2DMatrix(self, matrix, target) -> bool:
Console

Click Run to execute sample tests.