当前位置:网站首页>Search 2D matrix 2
Search 2D matrix 2
2022-07-01 18:34:00 【Free dreamer】

Search for a two-dimensional matrix
This problem is equivalent to a brain teaser , Just know how to do it ,ok
Ideas :
We can set the starting point to the upper right corner at the beginning ,
Here we can divide into three situations
1.t==target
2.t>target, If t>target, Then we can get rid of this column , because t The numbers below this column are greater than t
3.t<target, If t<target Then this line can be removed . Because in this business t Maximum .

step :
1. First create two variables to represent the coordinates of the upper right corner
2. Then take the condition that the coordinates of the point cannot cross the boundary as the cycle , Start the cycle
3. With t Represents the coordinate value , First three situations .
class Solution {
public:
bool searchMatrix(vector<vector<int>>& a, int target) {
if(a.empty()||a[0].empty())return false;
int n=a.size(),m=a[0].size();
int i=0,j=m-1;
while(i<n&&j>=0){
int t=a[i][j];
if(t==target)return true;
else if(t>target)j--;
else i++;
}
return false;
}
};
边栏推荐
- Step size of ode45 and reltol abstol
- Redis主从实现10秒检查与恢复
- Mysql database design
- Relationship between sensor size, pixel, dpi resolution, inch and millimeter
- How to retrieve the password for opening Excel files
- How to learn automated testing?
- Depth first search - DFS (burst search)
- Is it safe to open a securities account? Is there any danger
- Cloud computing - make learning easier
- Redis master-slave realizes 10 second check and recovery
猜你喜欢

People help ant help task platform repair source code

主成分之综合竞争力案例分析
![[beauty detection artifact] come on, please show your unique skill (is this beauty worthy of the audience?)](/img/e8/f43f5583e330fbc0cb6c0188711707.jpg)
[beauty detection artifact] come on, please show your unique skill (is this beauty worthy of the audience?)

Oracle TRUNC function processing date format

Thinkphp6 - CMS multi wechat management system source code

t10_ Adapting to Market Participantsand Conditions

Wechat applet blind box - docking wechat payment

Set the style of QT property sheet control

Database - MySQL advanced SQL statement (I)

Kernel stray cat stray dog pet adoption platform H5 source code
随机推荐
Data query language (DQL)
Work and leisure suggestions of old programmers
Highly reliable program storage and startup control system based on anti fuse FPGA and QSPI flash
Leetcode problem solving series -- continuous positive sequence with sum as s (sliding window)
Source code of new campus errand / campus task platform on mutual station
MFC obtains local IP (used more in network communication)
Relationship between sensor size, pixel, dpi resolution, inch and millimeter
PTA year of birth
Session layer of csframework, server and client (1)
Develop those things: add playback address authentication to easycvr platform
Irradiance, Joule energy, exercise habits
因子分析怎么计算权重?
Review Net 20th anniversary development and 51aspx growth
Fix the problem that easycvr device video cannot be played
Localization through custom services in the shuttle application
Redis主从实现10秒检查与恢复
PIP version problems: PIP problems still occur when installing akshare and using Tsinghua source and Douban source
Terms related to K line
Growing up in the competition -- (Guangyou's most handsome cub) Pikachu walking
On the language internationalization of Yongzhong Office