240. 搜索二维矩阵 II


思路

遍历每一行,将当前行的数存放至哈希表中(in的时间复杂度O(1)),查询target是否存在当前行中,是直接返回

遍历结束都找不到target,则说明target不存在

python 复制代码
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
相关推荐
2401_8384725119 小时前
使用Python进行图像识别:CNN卷积神经网络实战
jvm·数据库·python
CoLiuRs19 小时前
语义搜索系统原理与实现
redis·python·向量·es
zhihuaba19 小时前
使用PyTorch构建你的第一个神经网络
jvm·数据库·python
u01092727119 小时前
Python Web爬虫入门:使用Requests和BeautifulSoup
jvm·数据库·python
Stream_Silver20 小时前
【Agent学习笔记3:使用Python开发简单MCP服务】
笔记·python
穿过锁扣的风20 小时前
零基础入门 Python 爬虫:从基础到实战,爬取虎扑 / 豆瓣 / 图片全掌握
开发语言·爬虫·python
Stream_Silver20 小时前
【Agent学习笔记2:深入理解Function Calling技术:从原理到实践】
笔记·python
love530love21 小时前
技术复盘:llama-cpp-python CUDA 编译实战 (Windows)
人工智能·windows·python·llama·aitechlab·cpp-python·cuda版本
逄逄不是胖胖21 小时前
《动手学深度学习》-60translate实现
人工智能·python·深度学习
橘颂TA21 小时前
【测试】自动化测试函数介绍——web 测试
python·功能测试·selenium·测试工具·dubbo