Foundamental operation
Q1 Search for a target value in the Young Matrix
public boolean find(int[][] matrix, int target) {
if (matrix == null || matrix.length == 0 || matrix[0].length == 0) {
return false;
}
int i = 0;
int j = matrix[0].length - 1;
while (j > 0 && i < matrix.length){
if (matrix[i][j] == target) return true;
if (matrix[i][j] < target) {
i++;
}
else {
j--;
}
}
return false;
}Last updated