classSolution:defsearchMatrix(self,matrix: List[List[int]],target:int) ->bool: m, n =len(matrix),len(matrix[0]) i, j =0, n -1while i < m and j >=0:if matrix[i][j] == target:returnTrueelif matrix[i][j] > target:# 比当前值大,横向往左进一格 j -=1else:# matrix[i][j] < target 比当前值小,纵向往下进一格 i +=1returnFalse