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
相关推荐
Han_han919几秒前
面向对象高级 继承(extends):
开发语言·python
华科大胡子1 小时前
Chrome安全机制深度解析
python
易标AI1 小时前
标书智能体(四)——提示词顺序优化,让缓存命中,输入成本直降10倍
人工智能·python·提示词·智能体·招投标
深耕AI1 小时前
【VS Code 中 Python 虚拟环境降级完整指南(含 uv 工具实战)】
开发语言·python·uv
→长歌1 小时前
2026Java面试30题精解
java·python·面试
Bert.Cai1 小时前
pymysql自动提交设置
开发语言·python
吃一根烤肠1 小时前
Python调试革命:用ChatGPT Copilot快速定位复杂bug
python·chatgpt·copilot
小白学大数据2 小时前
攻克滑动拼图反爬:Python 高效爬取网页图片实战案例
开发语言·爬虫·python
Demon--hx2 小时前
[LeetCode]100 链表-专题
算法·leetcode·链表