// Source : https://leetcode.com/problems/search-a-2d-matrix-ii/description/
// Author : Tianming Cao
// Date : 2018-01-27
public class SearchA2DMatrixII {
public boolean searchMatrix(int[][] matrix, int target) {
if (matrix == null || matrix.length == 0 || matrix[0].length == 0) {
return false;
} else {
int m=matrix.length;
int n=matrix[0].length;
int row=0;
int col=n-1;
while(row<m&&col>=0){
int rightTopNumber=matrix[row][col];
if(rightTopNumber==target){
return true;
}else if(target>rightTopNumber){
row++;
}else{
col--;
}
}
return false;
}
}
}