Solución
solution.tsTypeScript
function searchMatrix(matrix: number[][], target: number): boolean {
if (matrix.length === 0 || matrix[0].length === 0) {
return false;
}
const rows = matrix.length;
const cols = matrix[0].length;
let row = 0;
let col = cols - 1;
while (row < rows && col >= 0) {
const current = matrix[row][col];
if (current === target) {
return true;
}
if (current > target) {
col--;
} else {
row++;
}
}
return false;
}0respuestas