当前位置:网站首页>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;
}
};
边栏推荐
- Leetcode 1380. Lucky numbers in the matrix (save the minimum number of each row and the maximum number of each column)
- Fix the black screen caused by iPhone system failure
- Samba basic usage
- What is web application security testing technology?
- Three dimensional anti-terrorism Simulation Drill deduction training system software
- [CF1476F]Lanterns
- The latest intelligent factory MES management system software solution
- Basic concepts of binary tree
- Definition of rotation axis in mujoco
- Localization through custom services in the shuttle application
猜你喜欢

MySQL connection tools

How to retrieve the password for opening Excel files

Classpath classpath

Set the style of QT property sheet control
![Htt [ripro network disk link detection plug-in] currently supports four common network disks](/img/e4/c06b94243cdbe391b8b2124ff30789.jpg)
Htt [ripro network disk link detection plug-in] currently supports four common network disks

Localization through custom services in the shuttle application

Depth first search - DFS (burst search)

The new server is packaged with the source code of H5 mall with an operation level value of several thousand

Samba basic usage

Cloud picture says | distributed transaction management DTM: the little helper behind "buy buy buy"
随机推荐
Fresh, 2022 advanced Android interview must know 100 questions (interview questions + answer analysis)
[CF559E]Gerald and Path
Penetration practice vulnhub range Tornado
[CF1476F]Lanterns
Distributed task queue: Celery usage record
PTA year of birth
網上股票開戶安全嗎?是否可靠?
Is it safe to open a securities account? Is there any danger
Database - MySQL advanced SQL statement (I)
Relationship between sensor size, pixel, dpi resolution, inch and millimeter
Mujoco model learning record
主成分计算权重
Record 3 - the state machine realizes key control and measures the number of external pulses
主成分之综合竞争力案例分析
Product service, operation characteristics
[2. Basics of Delphi grammar] 4 Object Pascal operators and expressions
Review Net 20th anniversary development and 51aspx growth
PIP version problems: PIP problems still occur when installing akshare and using Tsinghua source and Douban source
(6) VIM editor MV cat redirection standard input and output more pipe symbols head tail
A database editing gadget that can edit SQLite database. SQLite database replaces fields. SQL replaces all values of a field in the database