2018-11-02 leetcode Search a 2D Matrix II Search a 2D Matrix IIzip Version - 52ms 1234567891011class Solution: def searchMatrix(self, matrix, target): """ :type matrix: List[List[int]] :type target: int :rtype: bool """ for line in zip(*matrix): if target in line: return True return False Another Version - 48ms 123456789101112131415161718class Solution: def searchMatrix(self, matrix, target): """ :type matrix: List[List[int]] :type target: int :rtype: bool """ if not matrix: return False m, n = len(matrix), len(matrix[0]) row, col = 0, n - 1 while row < m and col >= 0: if matrix[row][col] == target: return True if matrix[row][col] > target: col -= 1 else: row += 1 return False test code 123456789In [27]: s = Solution(); t = s.searchMatrix(m, 20)In [28]: tOut[28]: FalseIn [29]: s = Solution(); t = s.searchMatrix(m, 5)In [30]: tOut[30]: True leet code Newer Longest Increasing Subsequence Older Container With Most Water