题解 | #二维数组中的查找#
二维数组中的查找
http://www.nowcoder.com/practice/abc3fe2ce8e146608e868a70efebf62e
public class Solution {
public boolean Find(int target, int [][] array) {
if(array.length==0 || array[0].length==0) return false;
// 初始坐标为↙左下角
int x = 0;
int y = array.length - 1;
do{
int num = array[y][x];
if(num ==target) return true;
if(num < target) x++; // 当前坐标数字小于目标数字,向→右找
else y--; // 当前坐标数字大于目标数字,向↑上找
}while(y>=0 && x<array[0].length); // 直到找到上方边界或右侧边界
return false;
}
}