当前位置:网站首页>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;
}
}
边栏推荐
- 卷积神经网络简介
- 支持多模多态 GBase 8c数据库持续创新重磅升级
- [turn to] MySQL operation practice (I): Keywords & functions
- The number of enclaves
- Pointnet++ learning
- Remote upgrade afraid of cutting beard? Explain FOTA safety upgrade in detail
- Gbase database helps the development of digital finance in the Bay Area
- High precision subtraction
- sync.Mutex源码解读
- 剑指 Offer 35.复杂链表的复制
猜你喜欢
远程升级怕截胡?详解FOTA安全升级
To be continued] [UE4 notes] L4 object editing
[trans]: spécification osgi
[to be continued] [depth first search] 547 Number of provinces
National teacher qualification examination in the first half of 2022
剑指 Offer 53 - I. 在排序数组中查找数字 I
Chapter 6 data flow modeling - after class exercises
一个新的微型ORM开源框架
To the distance we have been looking for -- film review of "flying house journey"
Heap sort summary
随机推荐
On-off and on-off of quality system construction
SSH password free login settings and use scripts to SSH login and execute instructions
lxml.etree.XMLSyntaxError: Opening and ending tag mismatch: meta line 6 and head, line 8, column 8
挂起等待锁 vs 自旋锁(两者的使用场合)
Talking about JVM (frequent interview)
Time complexity and space complexity
A preliminary study of sdei - see the essence through transactions
Yolov5 adds attention mechanism
Support multi-mode polymorphic gbase 8C database continuous innovation and heavy upgrade
kubeadm系列-01-preflight究竟有多少check
[to be continued] [UE4 notes] L3 import resources and project migration
GBase数据库助力湾区数字金融发展
卷积神经网络——卷积层
High precision subtraction
Introduction to tools in TF-A
kubeadm系列-00-overview
Corridor and bridge distribution (csp-s-2021-t1) popular problem solution
Csp-j-2020-excellent split multiple solutions
Reverse one-way linked list of interview questions
支持多模多态 GBase 8c数据库持续创新重磅升级