*This code describes how to find a lucky number in a matrix. *
const luckyNumber = (matrix)=>{
let num = []
for (let i = 0; i < matrix.length; i++) {
let arr = matrix[i];
let rowMax = Math.min(...arr);
let columnIndex = matrix[i].indexOf(rowMax);
let column = matrix.map((row) => row[columnIndex]);
let columnMax = Math.max(...column);
if (rowMax === columnMax) {
num.push(rowMax);
}
}
return num;
}
The above is the detailed content of Lucky Numbers in a Matrix. For more information, please follow other related articles on the PHP Chinese website!