当前位置:网站首页>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;
}
}
边栏推荐
- 剑指 Offer 53 - I. 在排序数组中查找数字 I
- Haut OJ 1347: addition of choice -- high progress addition
- To the distance we have been looking for -- film review of "flying house journey"
- 游戏商城毕业设计
- Maximum number of "balloons"
- Solon Auth 认证框架使用演示(更简单的认证框架)
- A misunderstanding about the console window
- [speed pointer] 142 circular linked list II
- [interval problem] 435 Non overlapping interval
- Remote upgrade afraid of cutting beard? Explain FOTA safety upgrade in detail
猜你喜欢

2022年上半年国家教师资格证考试

Acwing 4300. Two operations

lxml.etree.XMLSyntaxError: Opening and ending tag mismatch: meta line 6 and head, line 8, column 8

Solution to the palindrome string (Luogu p5041 haoi2009)

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

YOLOv5-Shufflenetv2

SAP method of modifying system table data

SAP-修改系统表数据的方法

远程升级怕截胡?详解FOTA安全升级
随机推荐
26、 File system API (device sharing between applications; directory and file API)
每日一题-无重复字符的最长子串
[to be continued] [UE4 notes] L3 import resources and project migration
kubeadm系列-00-overview
Demonstration of using Solon auth authentication framework (simpler authentication framework)
Maximum number of "balloons"
YOLOv5-Shufflenetv2
远程升级怕截胡?详解FOTA安全升级
Haut OJ 1221: a tired day
Bubble sort summary
卷积神经网络简介
What is the agile proportion of PMP Exam? Dispel doubts
[to be continued] [UE4 notes] L1 create and configure items
Shell Sort
Corridor and bridge distribution (csp-s-2021-t1) popular problem solution
SAP method of modifying system table data
Find a good teaching video for Solon framework test (Solon, lightweight application development framework)
用STM32点个灯
Solon 框架如何方便获取每个请求的响应时间?
[turn to] MySQL operation practice (I): Keywords & functions