1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23
|
var searchMatrix = function(matrix: [][], target: number) { let row = matrix.length; if(row === 0) return false let col = matrix.slice(-1)[0].length; if(col === 0) return false let i = 0; let r = row - 1; while(r >= 0 && i < col) { if(matrix[r][i] === target) return true if(matrix[r][i] < target) { i++ }else { r-- } } return false };
|