int h = size / 2;
    for (int x = offsetX; x < offsetX + size; x++) {
        for (int y = offsetY; y < offsetY + size; y++) {
            if (arr[y][x] != arr[offsetY][offsetX]) {
                return count(offsetX, offsetY, h, arr)
                        .add(count(offsetX + h, offsetY, h, arr))
                        .add(count(offsetX, offsetY + h, h, arr))
                        .add(count(offsetX + h, offsetY + h, h, arr));
            }
        }
    }

    이렇게 재귀 메서드를 구현한 후에는 solution() 메서드에서 다음과 같이 정사각형 전체 범위로 count() 메서드를 호출해서 전체 범위를 압축한 결과를 얻을 수 있습니다.

    public int[] solution(int[][] arr) {
        Count count = count(0, 0, arr.length, arr);
        return new int[] {count.zero, count.one};
    }
    신간 소식 구독하기
    뉴스레터에 가입하시고 이메일로 신간 소식을 받아 보세요.