当前位置:网站首页>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
边栏推荐
- 这三个 Go 水平自测题,你手写不出来还是先老实上班吧,过来看看
- What are the five common data types of Redis?What is the corresponding data storage space?Take you to learn from scratch
- ArcMAP出现-15的问题无法访问[Provide your license server administrator with the following information:Err-15]
- 金山云要飘到哪里?
- Real-time data warehouse practice of Baidu user product flow and batch integration
- 一文详解 implementation api embed
- 47Haproxy集群
- Merge similar items in LeetCode simple questions
- 没有接班人,格力只剩“明珠精选”
- 解决 idea 单元测试不能使用Scanner
猜你喜欢
Does face attendance choose face comparison 1:1 or face search 1:N?
百度用户产品流批一体的实时数仓实践
加密游戏:游戏的未来
IM即时通讯开发WebSocket从入门到精通
没有接班人,格力只剩“明珠精选”
The 6th "Blue Hat Cup" National College Student Network Security Skills Competition Semi-Final Part WriteUp
Merge similar items in LeetCode simple questions
人脸考勤是选择人脸比对1:1还是人脸搜索1:N?
一文详解 implementation api embed
燃炸!字节跳动成功上岸,只因刷爆LeetCode算法面试题
随机推荐
47Haproxy集群
mSystems | 中农汪杰组揭示影响土壤“塑料际”微生物群落的机制
漏洞管理计划的未来趋势
Real-time data warehouse practice of Baidu user product flow and batch integration
[Collection] HashSet and ArrayList lookup Contains() time complexity
10 款更先进的开源命令行工具
Twikoo腾讯云函数部署转移到私有部署
多线程下自旋锁设计基本思想
[List merge] Combine multiple lists into one list
面试美团被问到了Redis,搞懂这几个问题,让你轻松吊打面试官
Excel function formulas - LOOKUP function
吃透Chisel语言.36.Chisel实战之以FIFO为例(一)——FIFO Buffer和Bubble FIFO的Chisel实现
查看 CUDA cudnn 版本 & 测试 cuda 和 cudnn 有效性「建议收藏」
AtCoder Beginner Contest 077 D - Small Multiple
es6-promise对象详解
用低代码驱动IT现代化
如何培养ui设计师的设计思维?
Polygon zkEVM工具——PIL和CIRCOM
【list合并】多个list合并为一个list
协程与任务