LeetCode - 1380. Lucky Numbers in a Matrix

henu·2023년 12월 29일
0

LeetCode

목록 보기
157/186

Solution

var luckyNumbers  = function(matrix) {
    const minList = []
    const maxList = []

    for(let i=0; i<matrix.length; i++) {
        minList.push(Math.min(...matrix[i]))
    }

    for(let i=0; i<matrix[0].length; i++) {
        const col = []

        for(let j=0; j<matrix.length; j++) {
            col.push(matrix[j][i])
        }

        maxList.push(Math.max(...col))
    }

    return maxList.filter(e => minList.includes(e))
};

Explanation

0개의 댓글