작성
·
210
·
수정됨
0
function solution(arr) {
let result = Number.MIN_SAFE_INTEGER;
let row = 0;
let column = new Array(arr.length).fill(0);
let diagonal = new Array(2).fill(0);
let miniDia1 = 0; /** 대각의 합 */
let miniDia2 = 0;
for (let i = 0; i < arr.length; i++) {
let miniRow = 0; /** 행의 합 */
let miniCol = 0; /** 열의 합 */
for (let r = 0; r < arr.length; r++) {
miniRow += arr[i][r];
miniCol += arr[r][i];
if (miniRow > row) row = miniRow;
};
miniDia1 += arr[i][i];
miniDia2 += arr[i][arr.length - 1 - i];
column[i] = miniCol;
};
diagonal[0] = miniDia1;
diagonal[1] = miniDia2;
const maxCol = Math.max(...column);
const maxDia = Math.max(...diagonal);
result = Math.max(maxCol, maxDia, row);
return result;
};