题解 | #二维数组中的查找#
二维数组中的查找
https://www.nowcoder.com/practice/abc3fe2ce8e146608e868a70efebf62e
public class Solution {
public boolean Find(int target, int [][] array) {
int rows = array.length;
int cols = array[0].length;
int i, j;
for (int row = rows - 1, col = 0; row >= 0 && row < rows && col >= 0 &&
col < cols;) {
if (array[row][col] == target) return true;
if (array[row][col] < target) {
col++;
continue;
}
if (array[row][col] > target) {
row--;
continue;
}
}
return false;
}
}
解题思想:双指针
#算法笔记##算法#
查看9道真题和解析