当前位置:网站首页>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;
}
}
边栏推荐
- 软件测试 -- 0 序
- Demonstration of using Solon auth authentication framework (simpler authentication framework)
- sync.Mutex源码解读
- [merge array] 88 merge two ordered arrays
- How can the Solon framework easily obtain the response time of each request?
- 动漫评分数据分析与可视化 与 IT行业招聘数据分析与可视化
- [to be continued] [depth first search] 547 Number of provinces
- On-off and on-off of quality system construction
- [转]: OSGI规范 深入浅出
- Under the national teacher qualification certificate in the first half of 2022
猜你喜欢

剑指 Offer 05. 替换空格

Web APIs DOM节点
![[to be continued] [UE4 notes] L3 import resources and project migration](/img/81/6f75f8fbe60e037b45db2037d87bcf.jpg)
[to be continued] [UE4 notes] L3 import resources and project migration

第六章 数据流建模—课后习题

质量体系建设之路的分分合合

剑指 Offer 04. 二维数组中的查找

Chapter 6 data flow modeling - after class exercises

YOLOv5添加注意力机制

Corridor and bridge distribution (csp-s-2021-t1) popular problem solution

Double pointer Foundation
随机推荐
sync. Interpretation of mutex source code
卷积神经网络——卷积层
Romance of programmers on Valentine's Day
剑指 Offer 04. 二维数组中的查找
Count sort
[merge array] 88 merge two ordered arrays
Pointnet++学习
Software test -- 0 sequence
【ES实战】ES上的native realm安全方式使用
Detailed explanation of expression (csp-j 2021 expr) topic
Binary search basis
On-off and on-off of quality system construction
PMP考试敏捷占比有多少?解疑
Double pointer Foundation
Haut OJ 1347: addition of choice -- high progress addition
Programmers' experience of delivering takeout
The number of enclaves
剑指 Offer 05. 替换空格
What is the agile proportion of PMP Exam? Dispel doubts
Reflection summary of Haut OJ freshmen on Wednesday