0
点赞
收藏
分享

微信扫一扫

防止电脑电池老化,禁止usb或者ac接口调试时充电

追风骚年 2024-09-25 阅读 1

在这里插入图片描述
思路

遍历每一行,将当前行的数存放至哈希表中(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
举报

相关推荐

0 条评论