当前位置:网站首页>Find out whether the number exists from the matrix
Find out whether the number exists from the matrix
2022-07-28 08:03:00 【The galloping snail has been occupied】
subject : A matrix , Increase from left to right , Increase from top to bottom ;
Look in the matrix , Whether the given number exists ;
analysis : Look at the matrix from left to right : In the rightmost row of the matrix , Is the largest in each row ,( Here comes the soul painter ) Pictured 
The first point in the upper right corner ( Referred to as A Click on it. ), There is a property , If you compare A It's a little big , If you can't find the number in the first row, you can only find it in the next row ; If you compare A Small , Can only move to the left ; When moving to the next point , You can still continue to judge with the above ideas ;
So this is the way to think about it , The worst result , Is in the lower left corner of the matrix : find / Did not find ;
that , The boundary of this algorithm is easy to determine ;
```
public boolean find(int target ,int[][] a){
int m = 0;
int n = a[0].length-1;
while(true){
if(m >a.length-1 || n <0){// The border ,
return false;
}
if(target == a[m][n]){// eureka , Go straight back to
return true;
}
if(target < a[m][n]){// Move left
n--;
continue;
}
if(target > a[m][n]){// Move right
m++;
continue;
}
}
}
边栏推荐
- DNA deoxyribonucleic acid modified platinum nanoparticles ptnps DNA | scientific research reagent
- What are the different tables in MySQL?
- Yaml parameter configuration based on singleton mode
- 近红外二区AgzS量子点包裹脱氧核糖核酸DNA|DNA-AgzSQDs(齐岳)
- EMC rectification ideas
- ArcGIS JS map internal and external network environment judgment
- YOLO系列损失函数详解
- Delete the nodes in the linked list - daily question
- Mysql, how can we get the number of rows affected by the query?
- Opentsdb time series database
猜你喜欢

EMC设计攻略 —时钟

GD32使用ST的HAL库和GD官方库的一些体会

@The role of documented

CLion调试redis6源码

Lecture notes a utility for everyone to generate PCG

JUC原子类: CAS, Unsafe、CAS缺点、ABA问题如何解决详解

ArcGIS JS customizes the accessor and uses the watchutils related method to view the attribute
C language explanation series - array explanation, one-dimensional array, two-dimensional array

Industry standards and certification of common electronic products

MPLS --- 多协议标签交换技术
随机推荐
Analysis of collector principle
谈谈DOM0,DOM1,DOM2,DOM3
【活动报名】云原生技术交流 Meetup,8 月 6 日广州见
Mechanical revolution Jiaolong P wired network card driver can't play
Understanding of spark operator aggregatebykey
Opentsdb time series database
XSS knowledge points and 20 character short domain name bypass
Record a MYCAT connection and solve the problems of communications link failure
What if the computer desktop icon has a small yellow lock?
[dry goods] 32 EMC standard circuits are shared!
These mobile security browsers are more than a little easy to use
Mysql中有哪些不同的表格?
Merge two sorted linked lists - two questions per day
Solve the inherent defects of CNN! Common CNN architecture ccnn is coming | icml2022
After being accidentally dragged into QQ fraud group
(daily question) - the longest substring without repeated characters
ArcGIS JS 地图内外网环境判断问题
Redis of non relational database [detailed setup of redis cluster]
Qt多线程中槽函数在哪个线程里执行分析
C language explanation series - array explanation, one-dimensional array, two-dimensional array