当前位置:网站首页>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;
}
}

边栏推荐
- Behavior perception system
- Clickpaas low code platform
- Use object composition in preference to class inheritance
- [phantom engine UE] package error appears! Solutions to findpin errors
- 【UNIAPP】系统热更新实现思路
- mxnet导入报各种libcudart*.so、 libcuda*.so找不到
- 这是一个不确定的时代
- web资源部署后navigator获取不到mediaDevices实例的解决方案(navigator.mediaDevices为undefined)
- [thingsboard] how to replace the homepage logo
- Get to know MySQL connection query for the first time
猜你喜欢

美国5G Open RAN再遭重大挫败,抗衡中国5G技术的图谋已告失败

【虚幻引擎UE】运行和启动的区别,常见问题分析

蛇形矩阵

Moco is not suitable for target detection? MsrA proposes object level comparative learning target detection pre training method SOCO! Performance SOTA! (NeurIPS 2021)...

基于TCP的移动端IM即时通讯开发仍然需要心跳保活

Containerd series - what is containerd?

【UNIAPP】系统热更新实现思路

JVM garbage collection

【虚幻引擎UE】实现UE5像素流部署仅需六步操作少走弯路!(4.26和4.27原理类似)

Network security - record web vulnerability fixes
随机推荐
Study notes 7
[phantom engine UE] package error appears! Solutions to findpin errors
Sequence diagram of single sign on Certification Center
Behavior perception system
A application wakes up B should be a fast method
OWASP top 10 vulnerability Guide (2021)
Alibaba cloud ECS uses cloudfs4oss to mount OSS
About the prompt loading after appscan is opened: guilogic, it keeps loading and gets stuck. My personal solution. (it may be the first solution available in the whole network at present)
学习MVVM笔记(一)
Learning MVVM notes (1)
Threejs loads the city obj model, loads the character gltf model, and tweetjs realizes the movement of characters according to the planned route
Machine learning -- neural network
Rome chain analysis
American 5g open ran suffered another major setback, and its attempt to counter China's 5g technology has failed
Pyqt pyside custom telescopic menu bar sharing (including tutorial)
【虚幻引擎UE】实现UE5像素流部署仅需六步操作少走弯路!(4.26和4.27原理类似)
The scale of computing power in China ranks second in the world: computing is leaping forward in Intelligent Computing
Rust区块琏开发——签名加密与私钥公钥
小程序中实现文章的关注功能
BDF application - topology sequence