""" Write an efficient algorithm that searches for a value in an m x n matrix. This matrix has the following properties:

    Integers in each row are sorted from left to right.
    The first integer of each row is greater than the last integer of the previous row.
"""

class Solution:
    def searchMatrix(self, matrix: List[List[int]], target: int) -> bool:
        if not matrix or target is None:
            return False

        rows, cols = len(matrix), len(matrix[0])
        low, high = 0, rows * cols - 1
        
        while low <= high:
            mid = (low + high) // 2
            num = matrix[mid // cols][mid % cols]

            if num == target:
                return True
            elif num < target:
                low = mid + 1
            else:
                high = mid - 1
        
        return False
    
    '''
    i = bisect.bisect(matrix, [target])
    if i < len(matrix) and matrix[i][0] == target:
        return True
    row = matrix[i-1]
    j = bisect.bisect_left(row, target)
    return j < len(row) and row[j] == target
    '''
4548ce262d385fb52b9a717608a1016c01891284
<mask token>

<mask token>


class Solution:
    <mask token>
    <mask token>

<mask token>


class Solution:

    def searchMatrix(self, matrix: List[List[int]], target: int) ->bool:
        if not matrix or target is None:
            return False
        rows, cols = len(matrix), len(matrix[0])
        low, high = 0, rows * cols - 1
        while low <= high:
            mid = (low + high) // 2
            num = matrix[mid // cols][mid % cols]
            if num == target:
                return True
            elif num < target:
                low = mid + 1
            else:
                high = mid - 1
        return False
    <mask token>

<mask token>


class Solution:

    def searchMatrix(self, matrix: List[List[int]], target: int) ->bool:
        if not matrix or target is None:
            return False
        rows, cols = len(matrix), len(matrix[0])
        low, high = 0, rows * cols - 1
        while low <= high:
            mid = (low + high) // 2
            num = matrix[mid // cols][mid % cols]
            if num == target:
                return True
            elif num < target:
                low = mid + 1
            else:
                high = mid - 1
        return False
    """
    i = bisect.bisect(matrix, [target])
    if i < len(matrix) and matrix[i][0] == target:
        return True
    row = matrix[i-1]
    j = bisect.bisect_left(row, target)
    return j < len(row) and row[j] == target
    """

""" Write an efficient algorithm that searches for a value in an m x n matrix. This matrix has the following properties:

    Integers in each row are sorted from left to right.
    The first integer of each row is greater than the last integer of the previous row.
"""

class Solution:
    def searchMatrix(self, matrix: List[List[int]], target: int) -> bool:
        if not matrix or target is None:
            return False

        rows, cols = len(matrix), len(matrix[0])
        low, high = 0, rows * cols - 1
        
        while low <= high:
            mid = (low + high) // 2
            num = matrix[mid // cols][mid % cols]

            if num == target:
                return True
            elif num < target:
                low = mid + 1
            else:
                high = mid - 1
        
        return False
    
    '''
    i = bisect.bisect(matrix, [target])
    if i < len(matrix) and matrix[i][0] == target:
        return True
    row = matrix[i-1]
    j = bisect.bisect_left(row, target)
    return j < len(row) and row[j] == target
    '''