当前位置:网站首页>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;
}
};
边栏推荐
- PTA year of birth
- The latest intelligent factory MES management system software solution
- The method of real-time tracking the current price of London Silver
- 证券开户安全么,有没有什么样的危险呢
- Apk signature process introduction [easy to understand]
- Vue uses keep alive to cache page optimization projects
- 網上股票開戶安全嗎?是否可靠?
- Penetration practice vulnhub range Keyring
- MES production equipment manufacturing execution system software
- 目前炒期货在哪里开户最正规安全?怎么期货开户?
猜你喜欢

Kernel stray cat stray dog pet adoption platform H5 source code

Product service, operation characteristics
![[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?)
![[today in history] February 15: Pascal's father was born; YouTube was founded; Kotlin language comes out](/img/f3/20b73f3545cdd17b9fbc52bf493ab4.jpg)
[today in history] February 15: Pascal's father was born; YouTube was founded; Kotlin language comes out

t10_ Adapting to Market Participantsand Conditions

Review Net 20th anniversary development and 51aspx growth

Blue Bridge Cup real topic: the shortest circuit

Common design parameters of solid rocket motor

Database - MySQL advanced SQL statement (I)

Computer network interview assault
随机推荐
Data query language (DQL)
Oracle TRUNC function processing date format
Mysql database design
Debiasing word embeddings | talking about word embedding and deviation removal # yyds dry goods inventory #
Distributed task queue: Celery usage record
L'ouverture d'un compte d'actions en ligne est - elle sécurisée? Fiable?
DRF --- response rewrite
js如何将带有分割符的字符串转化成一个n维数组
Fresh, 2022 advanced Android interview must know 100 questions (interview questions + answer analysis)
Is it safe to open a securities account? Is there any danger
An example of data analysis of an old swatch and an old hard disk disassembly and assembly combined with the sensor of an electromagnetic press
Htt [ripro network disk link detection plug-in] currently supports four common network disks
Leetcode problem solving series -- continuous positive sequence with sum as s (sliding window)
Leetcode 1380. Lucky numbers in the matrix (save the minimum number of each row and the maximum number of each column)
Product service, operation characteristics
The latest intelligent factory MES management system software solution
[CF559E]Gerald and Path
Setting up a time server requires the client to automatically synchronize the time of the server at 9 a.m. every day
Nearly 60% of the employees strongly support Ctrip's "3+2" working mode, and work at home for two days a week
[CF1476F]Lanterns