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
相关推荐
2501_9411440340 分钟前
人工智能赋能智慧交通互联网应用:智能出行与交通管理优化实践探索》
leetcode
CNRio1 小时前
ZUC国密算法深度研究:原理、实现与应用(Python、Rust)
python·算法·rust
Python大数据分析@2 小时前
数据分析为什么常用Jupyter而不是直接使用Python脚本或Excel?
python·jupyter·数据分析
一株菌子2 小时前
10.9总结
开发语言·python
o***Z4482 小时前
Python包管理工具
开发语言·python
做怪小疯子2 小时前
LeetCode 热题 100——普通数组——除自身以外数组的乘积
数据结构·算法·leetcode
虹科网络安全3 小时前
艾体宝干货 | Redis Python 开发系列#4 保证原子性与性能
redis·python·junit
G***T6913 小时前
Python混合现实案例
python·pygame·mr
FreeCode3 小时前
LangGraph1.0智能体开发:选择API
python·langchain·agent
好学且牛逼的马3 小时前
【Java编程思想|15-泛型】
java·windows·python