Leetcode 74 Posted on 2019-04-27 | | 阅读数 Words count in article: 94 | Reading time ≈ 1 Question Solution因为matrix是排好序的,将其转化为一维列表,然后用二分法查找。 1234567891011121314151617class Solution: def searchMatrix(self, matrix: List[List[int]], target: int) -> bool: if not matrix: return False if not matrix[0]: return False temp = [elem for row in matrix for elem in row] first, last = 0, len(temp) - 1 while first <= last: mid = (first + last) // 2 if temp[mid] == target: return True elif temp[mid] < target: first = mid + 1 else: last = mid - 1 return False