본문 바로가기
Coding Test/Programmers

[Programmers] (2018 KAKAO BLIND RECRUITMENT) Lv 2. [1차] 프렌즈4블록

by song.ift 2023. 3. 6.

https://school.programmers.co.kr/learn/courses/30/lessons/17679

 

프로그래머스

코드 중심의 개발자 채용. 스택 기반의 포지션 매칭. 프로그래머스의 개발자 맞춤형 프로필을 등록하고, 나와 기술 궁합이 잘 맞는 기업들을 매칭 받으세요.

programmers.co.kr

 

javascript
닫기
function solution(m, n, board) { ​​​​const dirX = [0, 1, 1, 0], // 시계 방향 ​​​​​​​​dirY = [0, 0, 1, 1]; ​​​​board = board.map((v) => v.split("")); ​​​​do { ​​​​​​​​const remove = []; ​​​​​​​​for (let i = 0; i < m - 1; ++i) { ​​​​​​​​​​​​for (let j = 0; j < n - 1; ++j) { ​​​​​​​​​​​​​​​​if (board[i][j] === 0) continue; ​​​​​​​​​​​​​​​​const checkBlocks = Array.from({ length: dirX.length }, (_, idx) => [i + dirY[idx], j + dirX[idx]]); ​​​​​​​​​​​​​​​​if (checkBlocks.every(([x, y]) => board[x][y] === board[i][j])) checkBlocks.forEach(([x, y]) => remove.push([x, y])); ​​​​​​​​​​​​} ​​​​​​​​} ​​​​​​​​if (!remove.length) break; ​​​​​​​​remove.forEach(([x, y]) => board[x][y] = 0); ​​​​​​​​for (let i = m - 1; i > 0; --i) { ​​​​​​​​​​​​if (!board[i].some((e) => !e)) continue; ​​​​​​​​​​​​for (let j = 0; j < n; ++j) { ​​​​​​​​​​​​​​​​for (let k = i - 1; k >= 0 && !board[i][j]; --k) { ​​​​​​​​​​​​​​​​​​​​if (board[k][j]) { ​​​​​​​​​​​​​​​​​​​​​​​​board[i][j] = board[k][j]; ​​​​​​​​​​​​​​​​​​​​​​​​board[k][j] = 0; ​​​​​​​​​​​​​​​​​​​​​​​​break; ​​​​​​​​​​​​​​​​​​​​} ​​​​​​​​​​​​​​​​} ​​​​​​​​​​​​} ​​​​​​​​} ​​​​} while (true) ​​​​return [].concat(...board).filter((e) => !e).length; }

GitHub : https://github.com/developeSHG/Algorithm-Baekjoon_Programmers/tree/main/%ED%94%84%EB%A1%9C%EA%B7%B8%EB%9E%98%EB%A8%B8%EC%8A%A4/lv2/17679.%E2%80%85%EF%BC%BB1%EC%B0%A8%EF%BC%BD%E2%80%85%ED%94%84%EB%A0%8C%EC%A6%884%EB%B8%94%EB%A1%9D

 

GitHub - developeSHG/Algorithm-Baekjoon_Programmers: 백준 and 프로그래머스 소스코드

백준 and 프로그래머스 소스코드. Contribute to developeSHG/Algorithm-Baekjoon_Programmers development by creating an account on GitHub.

github.com

 

댓글