package divide_and_conquer;
public class leetcode_240 {
public static void main(String[] args) {
int[][] matrix = {{1,4,7,11,15},{2,5,8,12,19},{3,6,9,16,22},{10,13,14,17,24},{18,21,23,26,30}};
System.out.println(searchMatrix(matrix, 5));
}
public static boolean searchMatrix(int[][] matrix, int target) {
if(matrix == null) {
return false;
}
if(matrix.length == 0) {
return false;
}
int rows = matrix.length;
int cols = matrix[0].length;
int i = 0;
int j = cols-1;
while(i<rows && j>=0 ) {
if(matrix[i][j] == target) {
return true;
}else if(matrix[i][j] > target) {
--j;
}else {
++i;
}
}
return false;
}
}