当前位置:网站首页>Sword finger offer 04 Search in two-dimensional array
Sword finger offer 04 Search in two-dimensional array
2022-07-05 05:28:00 【ThE wAlkIng D】
Title Description
Problem analysis
- Notice how the two-dimensional array is incremented , Locate the lower left corner as the starting point and start traversal according to the incremental method
- Be careful .length( For any array , Take out its capacity ) and .length()( For Strings ) The difference between
Code instance
class Solution {
public boolean findNumberIn2DArray(int[][] array, int target) {
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;
}
}
边栏推荐
猜你喜欢
Corridor and bridge distribution (csp-s-2021-t1) popular problem solution
Web APIs DOM node
剑指 Offer 53 - II. 0~n-1中缺失的数字
剑指 Offer 09. 用两个栈实现队列
The present is a gift from heaven -- a film review of the journey of the soul
一个新的微型ORM开源框架
lxml. etree. XMLSyntaxError: Opening and ending tag mismatch: meta line 6 and head, line 8, column 8
Service fusing hystrix
挂起等待锁 vs 自旋锁(两者的使用场合)
剑指 Offer 05. 替换空格
随机推荐
[turn to] MySQL operation practice (III): table connection
剑指 Offer 53 - I. 在排序数组中查找数字 I
YOLOv5添加注意力机制
[转]MySQL操作实战(三):表联结
Summary of Haut OJ 2021 freshman week
[allocation problem] 455 Distribute cookies
发现一个很好的 Solon 框架试手的教学视频(Solon,轻量级应用开发框架)
xftp7与xshell7下载(官网)
A problem and solution of recording QT memory leakage
[interval problem] 435 Non overlapping interval
SAP method of modifying system table data
FVP和Juno平台的Memory Layout介绍
Acwing 4300. Two operations
A preliminary study of sdei - see the essence through transactions
Haut OJ 1221: a tired day
Es module and commonjs learning notes -- ESM and CJS used in nodejs
sync. Interpretation of mutex source code
Demonstration of using Solon auth authentication framework (simpler authentication framework)
YOLOv5-Shufflenetv2
Reverse one-way linked list of interview questions