当前位置:网站首页>Daily question - Search two-dimensional matrix PS two-dimensional array search
Daily question - Search two-dimensional matrix PS two-dimensional array search
2022-07-05 05:28:00 【ThE wAlkIng D】
Title Description
In a two-dimensional array , Each row is sorted in ascending order from left to right , Each column is sorted in ascending order from top to bottom . Please complete a function , Enter such a two-dimensional array and an integer , Determine whether the array contains the integer .
Problem analysis
If you want to find the fastest , You need to traverse from the lower left corner of the matrix , Because from the lower left corner , The number goes up and down , The number gets bigger to the right , When the target value is larger than the search value , Move upward , When the target value is smaller than the search value , Move right
Code instance
public class Solution {
public boolean Find(int target, int [][] array) {
int row = array.length-1;
int col = 0;
while((row >= 0)&&(col < array[0].length)){
if(array[row][col] > target){
row--;
}else if(array[row][col] < target){
col++;
}else{
return true;
}
}
return false;
}
}
边栏推荐
- PMP考生,请查收7月PMP考试注意事项
- [转]: OSGI规范 深入浅出
- [转]MySQL操作实战(一):关键字 & 函数
- Under the national teacher qualification certificate in the first half of 2022
- kubeadm系列-00-overview
- Haut OJ 1321: mode problem of choice sister
- Fragment addition failed error lookup
- On-off and on-off of quality system construction
- 软件测试 -- 0 序
- 注解与反射
猜你喜欢
随机推荐
Haut OJ 1218: maximum continuous sub segment sum
挂起等待锁 vs 自旋锁(两者的使用场合)
kubeadm系列-02-kubelet的配置和启动
[trans]: spécification osgi
[转]: OSGI规范 深入浅出
【ES实战】ES上的native realm安全方式使用
软件测试 -- 0 序
[turn to] MySQL operation practice (I): Keywords & functions
Gbase database helps the development of digital finance in the Bay Area
sync. Interpretation of mutex source code
SDEI初探-透过事务看本质
二十六、文件系统API(设备在应用间的共享;目录和文件API)
每日一题-搜索二维矩阵ps二维数组的查找
Demonstration of using Solon auth authentication framework (simpler authentication framework)
kubeadm系列-00-overview
Es module and commonjs learning notes
xftp7与xshell7下载(官网)
Add level control and logger level control of Solon logging plug-in
To be continued] [UE4 notes] L4 object editing
Merge sort


![[merge array] 88 merge two ordered arrays](/img/e9/a73d9f22eead8e68c1e45c27ff6e6c.jpg)





![[turn]: OSGi specification in simple terms](/img/54/d73a8d3e375dfe430c2eca39617b9c.png)
