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
相关推荐
用户8356290780514 小时前
如何使用 Python 为 PDF 添加和管理图层
后端·python
祉猷并茂,雯华若锦4 小时前
Appium 3.x 实战:元素定位与常见错误解析
开发语言·python·appium
旖-旎4 小时前
《LeetCode 416 分割等和子集》
c++·算法·leetcode·动态规划·背包问题
jiang_changsheng5 小时前
Conda 的默认环境创建优先级。
linux·windows·python
FriendshipT5 小时前
Ultralytics:解读C2fCIB模块
人工智能·pytorch·python·深度学习·目标检测
c_lb72885 小时前
2026年AI量化学习流程,从表达开发走到分层验证
人工智能·python
s180579163625 小时前
低成本GEO优化技巧
人工智能·python
buhuizhiyuci6 小时前
【python篇——一周速通python语法】python的基础语法操作
开发语言·python
盼小辉丶6 小时前
OpenCV-Python实战——分析与加速OpenCV应用程序
python·神经网络·opencv·计算机视觉
buhuizhiyuci6 小时前
【python篇——一周速通python语法】python的条件语句和循环语句
开发语言·python