当前位置:网站首页>LeetCode medium topic search of two-dimensional matrix
LeetCode medium topic search of two-dimensional matrix
2022-08-10 12:56:00 【·The sea of stars】
Title
Write an efficient algorithm to determine whether a target value exists in an m x n matrix.The matrix has the following properties:
Integers in each line are in ascending order from left to right.
The first integer of each line is greater than the last integer of the previous line.
Example 1:
Input: matrix = [[1,3,5,7],[10,11,16,20],[23,30,34,60]], target = 3
Output: true
Example 2: 
Input: matrix = [[1,3,5,7],[10,11,16,20],[23,30,34,60]], target = 13
Output: false
Tip:
m == matrix.length
n == matrix[i].length
1 <= m, n <= 100
-10^4 <= matrix[i][j],target <= 10^4
Source: LeetCode
Solution ideas
The problem is not difficult. The intuitive idea is to directly flatten the matrix into a 1-dimensional array, and then use binary search.
class Solution:def searchMatrix(self, matrix: List[List[span>int]], target: int) -> bool:temp=[]for i in matrix:temp.extend(i)return temp[bisect.bisect(temp,target)-1]==target
边栏推荐
- StarRocks on AWS Review | Data Everywhere Series Event Shenzhen Station ended successfully
- 娄底干细胞制备实验室建设须知要求
- Chapter9 : De Novo Molecular Design with Chemical Language Models
- LeetCode中等题之比较版本号
- [List merge] Combine multiple lists into one list
- IM即时通讯开发WebSocket从入门到精通
- 娄底污水处理厂实验室建设管理
- 郭晶晶家的象棋私教,好家伙是个机器人
- An enhanced dynamic packet buffer management. The core part of the paper
- 16. Getting Started with Pytorch Lightning
猜你喜欢

three.js blur glass effect

Prada, big show?In the yuan in the universe that!

时间序列的数据分析(五):简单预测法

【黑马早报】雷军称低谷期曾想转行开酒吧;拜登正式签署芯片法案;软银二季度巨亏230亿美元;北京市消协约谈每日优鲜...

StarRocks on AWS Review | Data Everywhere Series Event Shenzhen Station ended successfully

A detailed explanation of implementation api embed

技术人必看!数据治理是什么?它对数据中台建设重要吗?

燃炸!字节跳动成功上岸,只因刷爆LeetCode算法面试题

如何培养ui设计师的设计思维?

iTextSharp操作PDF
随机推荐
专有云ABC Stack,真正的实力派!
Golang分布式应用之etcd
wirshark 常用操作及 tcp 三次握手过程实例分析
蚂蚁金服+拼多多+抖音+天猫(技术三面)面经合集助你拿大厂offer
可视化服务编排在金融APP中的实践
日记16
Merge similar items in LeetCode simple questions
CURRENT_TIMESTAMP(6) 函数是否存在问题?
人脸考勤是选择人脸比对1:1还是人脸搜索1:N?
Keithley DMM7510精准测量超低功耗设备各种运作模式功耗
LeetCode中等题之搜索二维矩阵
IM即时通讯开发WebSocket从入门到精通
把相亲角搬到海外,不愧是咱爸妈
实践为主,理论为辅!腾讯大佬MySQL高阶宝典震撼来袭!
金山云要飘到哪里?
部署项目半途而废后续
mSystems | 中农汪杰组揭示影响土壤“塑料际”微生物群落的机制
讯飞创意组别 全国选拔赛成绩公布说明
Chapter9 : De Novo Molecular Design with Chemical Language Models
48 the mysql database