当前位置:网站首页>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;
}
}
}
边栏推荐
- And is two numbers of S - two questions per day
- Chapter 01 introduction of [notes of Huashu]
- Huawei Senior Engineer -- BGP routing filtering and community attributes
- Lecture notes a utility for everyone to generate PCG
- Awk from introduction to earth (16) discussion on the types of awk variables -- about the two types of numbers and strings
- SWM32系列教程5-ADC应用
- PCB design skills of EMC
- DNA modified noble metal nanoparticles | DNA deoxyribonucleic acid modified metal palladium Pd nanoparticles pdnps DNA
- 【花书笔记】 之 Chapter01 引言
- XSS knowledge points and 20 character short domain name bypass
猜你喜欢

EMC rectification ideas

【活动报名】云原生技术交流 Meetup,8 月 6 日广州见

DNA modified osmium OS nanoparticles osnps DNA modified iridium nanoparticles irnps DNA

Huawei Senior Engineer -- BGP routing filtering and community attributes

Introduction to magnetic ring selection and EMC rectification skills

The cornerstone of EMC - complete knowledge of electromagnetic compatibility filtering!

Merge two sorted linked lists - two questions per day

Delete the nodes in the linked list - daily question

Flowable workflow all business concepts

Why is ESD protection so important for integrated circuits? How to protect?
随机推荐
JUC原子类: CAS, Unsafe、CAS缺点、ABA问题如何解决详解
Copper indium sulfide CuInSe2 quantum dots modified DNA (deoxyribonucleic acid) DNA cuinse2qds (Qiyue)
PCB design skills of EMC
DNA修饰金属锇Os纳米颗粒OsNPS-DNA|DNA修饰金属铱纳米颗粒IrNPS-DNA
MySQL view the memory size of a table
【300+精选大厂面试题持续分享】大数据运维尖刀面试题专栏(八)
4.1.4 why set the member variable to private
快速搭建DMHS DM之间双向同步
Swm32 series tutorial 5-adc application
对spark算子aggregateByKey的理解
Summary of RFID radiation test
华为高级工程师---BGP路由过滤及社团属性
Yaml parameter configuration based on singleton mode
What if the task manager is not fully displayed?
演讲笔记 适合所有人的实用程序生成 PCG
@The role of documented
What are the different tables in MySQL?
DNA-CuInSeQDs近红外CuInSe量子点包裹脱氧核糖核酸DNA
The penultimate node in the linked list - Double finger
Tensorflow uses deep learning (II)