본문 바로가기
Coding Test/Programmers

[Programmers] (월간 코드 챌린지 시즌1) Lv 2. 쿼드압축 후 개수 세기

by song.ift 2023. 3. 8.

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

 

프로그래머스

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

programmers.co.kr

 

const solution = (arr) => {
    return (quadTree = (arr, y, x, n, result) => {
        for (let i = y; i < y + n; ++i) {
            for (let j = x; j < x + n; ++j) {
                if (arr[y][x] !== arr[i][j]) {
                    n = Math.floor(n / 2);
                    for (let [ny, nx] of [[y, x], [y, x + n], [y + n, x], [y + n, x + n]])
                        result = quadTree(arr, ny, nx, n, result);
                    return result;
                }
            }
        }
        return arr[y][x] === 0
            ? [result[0] + 1, result[1]]
            : [result[0], result[1] + 1];
    })(arr, 0, 0, arr.length, [0, 0]);
};

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/68936.%E2%80%85%EC%BF%BC%EB%93%9C%EC%95%95%EC%B6%95%E2%80%85%ED%9B%84%E2%80%85%EA%B0%9C%EC%88%98%E2%80%85%EC%84%B8%EA%B8%B0

 

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

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

github.com

 

댓글