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
相关推荐
Swift社区2 分钟前
LeetCode 460 - LFU 缓存
算法·leetcode·缓存
2301_811958389 分钟前
服务器自己账号下安装conda
linux·python·conda
百***787510 分钟前
Mistral 3极速接入指南:3步上手+核心能力解析+避坑手册
人工智能·python·开源
LCG米12 分钟前
嵌入式Python开发:MicroPython在物联网硬件上的实战应用案例
python·单片机·物联网
nvd1114 分钟前
SQLAlchemy 2.0 类型注解指南:`Mapped` 与 `mapped_column`
python
让学习成为一种生活方式16 分钟前
AGAT v1.6.0 安装与使用--生信工具72
人工智能·python·机器学习
小陈phd18 分钟前
Python MCP 工具开发入门:Server、Client 和 LLM 集成
开发语言·python·github
ShenLiang202521 分钟前
识别SQL里的列名
大数据·人工智能·python
jijkck22 分钟前
python库--pyautogui————windows模拟鼠标键盘、图像自动匹配、按钮弹窗
python·windows 10
2501_9444522331 分钟前
外观设置 Cordova 与 OpenHarmony 混合开发实战
python