思路
遍历每一行,将当前行的数存放至哈希表中(in的时间复杂度O(1)),查询target是否存在当前行中,是直接返回
遍历结束都找不到target,则说明target不存在
class Solution(object):
def searchMatrix(self, matrix, target):
"""
:type matrix: List[List[int]]
:type target: int
:rtype: bool
"""
for i in range(len(matrix)):
s = set(matrix[i])
if target in s:
return True
return False
标签:return,matrix,int,List,矩阵,II,240,type,target
From: https://blog.csdn.net/huanxianxianshi/article/details/142315812