思路:从左下角开始,当前数比$target大则向上找,比$target小则从右找
class Solution {
/**
* @param Integer[][] $matrix
* @param Integer $target
* @return Boolean
*/
function findNumberIn2DArray($matrix, $target) {
$h = count($matrix);
$l = count($matrix[0]);
$m = $h-1;
$n = 0;
while($m >=0 && $n < $l){
if($matrix[$m][$n] == $target) return true;
if($matrix[$m][$n] > $target) $m--;
if($matrix[$m][$n] < $target) $n++;
}
return false;
}
}