当前位置:网站首页>Sword finger offer 04 Search in two-dimensional array
Sword finger offer 04 Search in two-dimensional array
2022-07-05 04:17:00 【xzystart】
In a n * m 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 an efficient function , Enter such a two-dimensional array and an integer , Determine whether the array contains the integer .
Example :
The existing matrix matrix as follows :
[
[1, 4, 7, 11, 15],
[2, 5, 8, 12, 19],
[3, 6, 9, 16, 22],
[10, 13, 14, 17, 24],
[18, 21, 23, 26, 30]
]
Given target = 5, return true.
Given target = 20, return false.
Limit :
0 <= n <= 1000
0 <= m <= 1000
class Solution {
public static boolean findNumberIn2DArray(int[][] matrix, int target) {
int cloumn= 0,row = matrix.length-1; // Position the subscript to the lower left corner of the matrix
// Because starting from the lower left corner or the upper right corner , That is, this array can be regarded as a binary search tree
while ((row>=0)&&cloumn<matrix[0].length){
// Traversing the binary search tree
if (matrix[row][cloumn] >target){
row--;
}else if (matrix[row][cloumn] < target){
cloumn++;
}else return true;
}
return false;
}
}

边栏推荐
- mxnet导入报各种libcudart*.so、 libcuda*.so找不到
- 网络安全-记录web漏洞修复
- open graph协议
- EasyCVR更改录像存储路径,不生成录像文件如何解决?
- Threejs factory model 3DMAX model obj+mtl format, source file download
- 我国算力规模排名全球第二:计算正向智算跨越
- Threejs loads the city obj model, loads the character gltf model, and tweetjs realizes the movement of characters according to the planned route
- Ffmepg usage guide
- [moteur illusoire UE] il ne faut que six étapes pour réaliser le déploiement du flux de pixels ue5 et éviter les détours! (4.26 et 4.27 principes similaires)
- CTF stegano practice stegano 9
猜你喜欢

行为感知系统

Threejs factory model 3DMAX model obj+mtl format, source file download

【虚幻引擎UE】打包报错出现!FindPin错误的解决办法

How does the applet solve the rendering layer network layer error?

我国算力规模排名全球第二:计算正向智算跨越

Why can't all browsers on my computer open web pages

kubernetes集群之调度系统

10种寻址方式之间的区别

OWASP top 10 vulnerability Guide (2021)

【虚幻引擎UE】运行和启动的区别,常见问题分析
随机推荐
laravel8 导出Excle文件
【虚幻引擎UE】运行和启动的区别,常见问题分析
Kwai, Tiktok, video number, battle content payment
Threejs factory model 3DMAX model obj+mtl format, source file download
How to remove installed elpa package
[phantom engine UE] only six steps are needed to realize the deployment of ue5 pixel stream and avoid detours! (the principles of 4.26 and 4.27 are similar)
Threejs Internet of things, 3D visualization of factory
Phpmailer reported an error: SMTP error: failed to connect to server: (0)
【虛幻引擎UE】實現UE5像素流部署僅需六步操作少走彎路!(4.26和4.27原理類似)
Uni app change the default component style
【虚幻引擎UE】实现UE5像素流部署仅需六步操作少走弯路!(4.26和4.27原理类似)
Is "golden nine and silver ten" the best time to find a job? Not necessarily
This is an age of uncertainty
学习MVVM笔记(一)
open graph协议
[finebi] the process of making custom maps using finebi
Hexadecimal to decimal
Scheduling system of kubernetes cluster
Use object composition in preference to class inheritance
DFS and BFS concepts of trees and graphs