当前位置:网站首页>Search 2D matrix
Search 2D matrix
2022-07-23 19:35:00 【char~lie】
Write an efficient algorithm to judge m x n Matrix , Is there a target value . The matrix has the following characteristics :
The integers in each row are arranged in ascending order from left to right .
The first integer in each row is greater than the last integer in the previous row .
source : Power button (LeetCode)
link :https://leetcode.cn/problems/search-a-2d-matrix
class Solution {
public:
bool searchMatrix(vector<vector<int>> &matrix, int target) {
int row=matrix.size();
int col=matrix[0].size();
if(row==0||col==0) return false;
int l=0,r=row*col-1;
while(l<r)
{
int mid=l+(r-l)/2;
if(matrix[mid/col][mid%col]<target)
{
l=mid+1;
}
else
{
r=mid;
}
}
return target==matrix[l/col][l%col]?true:false;
}
};
边栏推荐
- Tree learning summary
- C语言小项目 -- 通讯录(静态版+动态版+文件版)
- mysqldump导出内容如何不带 comment ?
- Detailed explanation of TCL scripting language (1)
- R语言使用ggpubr包的ggarrange函数将多幅图像组合起来、使用ggexport函数将可视化图像保存为bmp格式(width参数指定宽度、height参数指定高度、res参数指定分辨率)
- DHCP:在网络中防止 Rogue DHCP Server
- AtCoder Regular Contest 144【VP记录】
- elk笔记25--快速体验APM
- Lendingclub loan status business details current, charge off, issued, full paid, grace period
- PowerCLi 管理VMware vCenter 批量部署导出导入
猜你喜欢
随机推荐
.Net CLR R2R编译的原理简析
Industry analysis | logistics intercom
[Nuxt 3] (九)服务器路由
Ros2 self study notes: rviz visualization tool
Sui of the public chain (New Public chain project established by former Facebook /meta employees)
Technical scheme of face recognition system
Calculation of structure size (structure memory alignment)
还在用Xshell?你out了,推荐一个更现代的终端连接工具
Why are there Chinese materials and web pages for foreign chips?
TCL scripting language foundation (2)
Todo fix bug tag feature and other configurations
树学习总结
什么是弱网测试?为什么要进行弱网测试?怎么进行弱网测试?「建议收藏」
解密:智能化变电站中PTP时钟同步(北斗时钟服务器)
Using FRP to achieve intranet penetration
R语言筛选dataframe指定的数据列、R语言排除(删除)dataframe中的指定数据列(变量)
将本地镜像发布到阿里云仓库
Weights & Biases (一)
Summarize some recent tricks
BoundsChecker用法「建议收藏」





![[shutter -- layout] linear layout (row and column)](/img/0e/df0f4bce73dd9785cc843adaf371d0.png)



