当前位置:网站首页>LeetCode中等题之搜索二维矩阵
LeetCode中等题之搜索二维矩阵
2022-08-10 12:05:00 【·星辰大海】
题目
编写一个高效的算法来判断 m x n 矩阵中,是否存在一个目标值。该矩阵具有如下特性:
每行中的整数从左到右按升序排列。
每行的第一个整数大于前一行的最后一个整数。
示例 1:
输入:matrix = [[1,3,5,7],[10,11,16,20],[23,30,34,60]], target = 3
输出:true
示例 2:
输入:matrix = [[1,3,5,7],[10,11,16,20],[23,30,34,60]], target = 13
输出:false
提示:
m == matrix.length
n == matrix[i].length
1 <= m, n <= 100
-10^4 <= matrix[i][j], target <= 10 ^4
来源:力扣(LeetCode)
解题思路
题目难度不大,直观的思路就是直接将矩阵flatten为1维数组,然后利用二分查找即可。
class Solution:
def searchMatrix(self, matrix: List[List[int]], target: int) -> bool:
temp=[]
for i in matrix:
temp.extend(i)
return temp[bisect.bisect(temp,target)-1]==target
边栏推荐
- 可视化服务编排在金融APP中的实践
- MySQL索引的B+树到底有多高?
- Is there a problem with the CURRENT_TIMESTAMP(6) function?
- Samsung plans to start producing semiconductor components in Vietnam in 2023
- 娄底干细胞制备实验室建设须知要求
- Golang分布式应用之etcd
- [List merge] Combine multiple lists into one list
- 22年BATJ大厂必问面试题(复盘):JVM+微服务+多线程+锁+高并发
- 47Haproxy集群
- Common examples of regular expressions
猜你喜欢
Database management tool: dynamic read-write separation
dedecms supports one-click import of Word content
郭晶晶家的象棋私教,好家伙是个机器人
“68道 Redis+168道 MySQL”精品面试题(带解析)
中科院深圳先进技术院合成所赵国屏院士组2022年招聘启事
Chapter9 : De Novo Molecular Design with Chemical Language Models
10 款更先进的开源命令行工具
Solve the idea that unit tests cannot use Scanner
爱可可AI前沿推介(8.10)
制品库是什么?
随机推荐
odps sql 不支持 unsupported feature CREATE TEMPORARY
搜索--01
22年BATJ大厂必问面试题(复盘):JVM+微服务+多线程+锁+高并发
search--01
如何让别人看不懂你的 JS 代码?把你当大佬!
Polygon zkEVM工具——PIL和CIRCOM
这三个 Go 水平自测题,你手写不出来还是先老实上班吧,过来看看
日记16
第六届”蓝帽杯“全国大学生网络安全技能大赛半决赛部分WriteUp
Threshold-based filtering buffer management scheme in a shared buffer packet switch core part of the paper
Data Analysis of Time Series (5): Simple Prediction Method
MySQL相关问题整理
mSystems | 中农汪杰组揭示影响土壤“塑料际”微生物群落的机制
CV复习:空洞卷积
十八、一起学习Lua 调试(Debug)
阿里架构师整理一份企业级SSM架构实战文档,让你熟悉底层原理
48MySQL数据库基础
如何培养ui设计师的设计思维?
【论文+代码】PEBAL/Pixel-wise Energy-biased Abstention Learning for Anomaly Segmentation on Complex Urban Driving Scenes(复杂城市驾驶场景异常分割的像素级能量偏置弃权学习)
ASP.NET Core依赖注入系统学习教程:ServiceDescriptor(服务注册描述类型)