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
相关推荐
资深web全栈开发40 分钟前
LeetCode 3623. 统计梯形的数目 I
算法·leetcode·职场和发展·组合数学
Wise玩转AI8 小时前
Day 27|智能体的 UI 与用户交互层
人工智能·python·ui·ai·chatgpt·ai智能体
s***46988 小时前
【玩转全栈】----Django模板语法、请求与响应
数据库·python·django
云里雾里!9 小时前
力扣 209. 长度最小的子数组:滑动窗口解法完整解析
数据结构·算法·leetcode
runepic9 小时前
Python + PostgreSQL 批量图片分发脚本:分类、去重、断点续拷贝
服务器·数据库·python·postgresql
codists9 小时前
2025年11月文章一览
python
生而为虫9 小时前
31.Python语言进阶
python·scrapy·django·flask·fastapi·pygame·tornado
言之。9 小时前
Claude Code 实用开发手册
python
计算机毕设小月哥9 小时前
【Hadoop+Spark+python毕设】中国租房信息可视化分析系统、计算机毕业设计、包括数据爬取、Spark、数据分析、数据可视化、Hadoop
后端·python·mysql
2***c4359 小时前
Redis——使用 python 操作 redis 之从 hmse 迁移到 hset
数据库·redis·python