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
相关推荐
Navigator_Z3 小时前
LeetCode //C - 1206. Design Skiplist
c语言·算法·leetcode
码行山野赴时序归途3 小时前
三道经典数组题:从暴力到最优的算法思维
c语言·开发语言·数据结构·算法·leetcode
小陈的进阶之路3 小时前
Claude Code辅助测试:导入篇skills
python·自动化
whcyhhh5 小时前
头歌实践教学平台:大数据存储2023(六)
大数据·数据库·python
Navigator_Z5 小时前
LeetCode //C - 1209. Remove All Adjacent Duplicates in String II
c语言·算法·leetcode
for_ever_love__5 小时前
python基础语法学习: 闭包
开发语言·python·学习·闭包
ly76895 小时前
Python 全面入门:从核心语法到工程实践
开发语言·python
Niuguangshuo7 小时前
DeepFilterNet 3:端侧实时全带降噪的开源标杆
python
第一程序员7 小时前
AI 辅助编程的 7 个误区:把模型当高级搜索引擎是对它的最大浪费
python·rust·github
土司大王7 小时前
LeetCode hot100——合并两个有序链表
算法·leetcode·链表