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