-
TIL-2024.04.02 - 코테연습 - 바탕화면 정리(1).programmers> 기초/코테 연습 2024. 4. 3. 05:56
URL:
https://school.programmers.co.kr/learn/courses/30/lessons/161990#qna
내가 푼 코드:
// URL > https://school.programmers.co.kr/learn/courses/30/lessons/161990 const solution = (wallpaper) => { let xMin = 9999999; let yMin = 999999; let xMax = 0; let yMax = 0; for (let i = 0; i < wallpaper.length; i++) { for (let j = 0; j < wallpaper[i].length; j++) { if (wallpaper[i][j] === "#") { if (xMin > i) xMin = i; //-1 else if (xMax < i + 1) xMax = i + 1; if (yMin > j) yMin = j; else if (yMax < j + 1) yMax = j + 1; } } } if (yMin >= yMax) return [ xMin, yMin, xMin + 1, yMin + 1 ]; return [ xMin, yMin, xMax, yMax ]; }; console.log("result:: ", solution([ ".#...", "..#..", "...#." ])); // [ 0, 1, 3, 4 ] console.log("result:: ", solution([ "..........", ".....#....", "......##..", "...##.....", "....#....." ])); // [1, 3, 5, 8] console.log("result:: ", solution([ ".##...##.", "#..#.#..#", "#...#...#", ".#.....#.", "..#...#..", "...#.#...", "....#...." ])); //[0, 0, 7, 9] console.log("result:: ", solution([ "..", "#." ])); // [1, 0, 2, 1];
'> 기초 > 코테 연습' 카테고리의 다른 글
TIL-2024.04.04 - 코테연습 - 공원 산책(1).programmers (0) 2024.04.04 TIL-2024.04.03 - 코테연습 - 달리기 연습(1).programmers (0) 2024.04.03 TIL-2024.03.31 - 코테연습 - kakao -압축(2).programmers (0) 2024.03.31 TIL-2024.03.30 - 코테연습 - kakao -뉴스 클러스터링(2).programmers (0) 2024.03.31 TIL-2024.03.29 - 코테연습 - 둘만의암호(1) .programmers (0) 2024.03.29