✨ 바탕화면 정리




나의 풀이
function solution(wallpaper) {
let lux = wallpaper.length;
let luy = wallpaper[0].length;
let rdx = 0;
let rdy = 0;
for(let i = 0; i < wallpaper.length; i++){
for(let j = 0; j < wallpaper[i].length; j++){
if(wallpaper[i][j] === '#'){
lux = Math.min(lux, i);
luy = Math.min(luy, j);
rdx = Math.max(rdx, i);
rdy = Math.max(rdy, j);
}
}
}
return [lux, luy, rdx + 1, rdy + 1];
}
다른사람의 풀이
function solution(wallpaper) {
let left = [];
let top = [];
let right = []
let bottom = [];
wallpaper.forEach((v,i) => {
[...v].forEach((val,ind) => {
if(val === "#") {
left.push(i)
top.push(ind)
right.push(i + 1)
bottom.push(ind + 1)
}
})
})
return [Math.min(...left), Math.min(...top), Math.max(...right), Math.max(...bottom)]
}