function solution(board) {
var answer = 0;
let temp = board
const boom = [[-1,1],[0,1],[1,1],
[-1,0], [1,0],
[-1,-1],[0,-1],[1,-1]]
for(let i = 0; i < board.length; i++){
for(let j = 0; j < board[i].length; j++){
if(temp[i][j] == 1){
boom.forEach((item)=>{
let [x,y] = item
x = x + i
y = y + j
if(x >= 0 && x < temp.length && y >= 0 && y < temp[i].length && temp[x][y] == 0){
temp[x][y] = 2
}
})
}
}
}
temp.forEach((item)=>{
item.forEach((e)=>{
if(e === 0){
answer++
}
})
})
return answer;
}
폭탄이 있는 위치를 [0, 0]으로 잡고 폭발 범위 생성하고, temp[i][j]를 확인하려 1을 찾습니다.
boom을 순회하며 폭발 범위를 더하여 temp폭발 범위 위치를 찾습니다.
그래서 0인 부분만 2로 바꾸어줍니다. 마지막으로 0의 개수를 구합니다.