题解 | #二维数组中的查找#
二维数组中的查找
http://www.nowcoder.com/practice/abc3fe2ce8e146608e868a70efebf62e
记录
public class Solution {
public boolean Find(int target, int [][] array) {
int rows = array.length;
if (rows == 0){
return false;
}
int cols = array[0].length;
if (cols == 0){
return false;
}
int row = 0;
int col = cols - 1;
while (row < rows && col >= 0){
if (target > array[row][col]){
row++;
} else if (target < array[row][col]){
col--;
} else {
return true;
}
}
return false;
}
}