https://school.programmers.co.kr/learn/courses/30/lessons/92344
링크 참고
function solution(board, skill) {
const nBoard = Array.from({length: board.length + 1}, () => Array.from({length: board[0].length + 1 }, _ => 0))
for (const [type, r1, c1, r2, c2, degree] of skill) {
const d = type === 1 ? -degree : degree
nBoard[r1][c1] += d
nBoard[r2 + 1][c1] -= d
nBoard[r1][c2 + 1] -= d
nBoard[r2 + 1][c2 + 1] += d
}
// 누적 합
for (let i = 0; i < board.length; i++) {
for (let j = 0; j < board[0].length; j++){
nBoard[i + 1][j] += nBoard[i][j]
}
}
for (let i = 0; i < board.length; i++) {
for (let j = 0; j < board[0].length; j++){
nBoard[i][j + 1] += nBoard[i][j]
}
}
for (let i = 0; i < board.length; i++) {
for (let j = 0; j < board[0].length; j++){
board[i][j] += nBoard[i][j]
}
}
return board.map((row) => row.filter((v) => v > 0).length).reduce((a, c) => a + c, 0)
}