当前位置:网站首页>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

边栏推荐
- 娄底植物细胞实验室建设基本组成要点
- Overseas media publicity. What problems should domestic media pay attention to?
- Deploy the project halfway through the follow-up
- 什么是云流化?
- The 6th "Blue Hat Cup" National College Student Network Security Skills Competition Semi-Final Part WriteUp
- How to do foreign media publicity to grasp the key points
- Chapter9 : De Novo Molecular Design with Chemical Language Models
- phpstrom 快速注释:
- three.js blur glass effect
- 部署项目半途而废后续
猜你喜欢

16、Pytorch Lightning入门
![ArcMAP出现-15的问题无法访问[Provide your license server administrator with the following information:Err-15]](/img/da/b49d7ba845c351cefc4efc174de995.png)
ArcMAP出现-15的问题无法访问[Provide your license server administrator with the following information:Err-15]

培训机构学习费用是多少呢?

太香了!自从用了这款接口神器,我的团队效率提升了 60%!

你是怎么知道数据库 Htap 能力强弱的?怎么能看出来

mpf6_Time Series Data_quandl_correct kernel PCA_AIC_BIC_trend_log_return_seasonal_decompose_sARIMAx_ADFull

人脸考勤是选择人脸比对1:1还是人脸搜索1:N?

Data Analysis of Time Series (5): Simple Prediction Method

CURRENT_TIMESTAMP(6) 函数是否存在问题?

CLIP还能做分割任务?哥廷根大学提出一个使用文本和图像prompt,能同时作三个分割任务的模型CLIPSeg,榨干CLIP能力...
随机推荐
Deploy the project halfway through the follow-up
[Collection] HashSet and ArrayList lookup Contains() time complexity
可视化服务编排在金融APP中的实践
StarRocks on AWS 回顾 | Data Everywhere 系列活动深圳站圆满结束
IM即时通讯开发WebSocket从入门到精通
Threshold-based filtering buffer management scheme in a shared buffer packet switch core part of the paper
leetcode/两个链表的第一个重合节点
【论文+代码】PEBAL/Pixel-wise Energy-biased Abstention Learning for Anomaly Segmentation on Complex Urban Driving Scenes(复杂城市驾驶场景异常分割的像素级能量偏置弃权学习)
Samsung plans to start producing semiconductor components in Vietnam in 2023
So delicious!Since using this interface artifact, my team efficiency has increased by 60%!
浮动及其特点
2016,还是到了最后
搜索--01
Configuration swagger
LeetCode 82. Remove Duplicate Elements in Sorted List II
【list合并】多个list合并为一个list
LeetCode 237. Delete a node in a linked list
wirshark 常用操作及 tcp 三次握手过程实例分析
漏洞管理计划的未来趋势
tommy's spell