Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit e4afdbe

Browse files
Merge pull request #96 from codeisneverodd/codeisneverodd
feat: 2 / 쿼드 압축 후 개수 세기 / 새로운 문제
2 parents f029680 + a92c5ef commit e4afdbe

File tree

1 file changed

+25
-0
lines changed

1 file changed

+25
-0
lines changed
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
//https://github.com/codeisneverodd/programmers-coding-test
2+
//더 좋은 풀이가 존재할 수 있습니다.
3+
//정답 1 - 본인의 깃허브 아이디
4+
function solution(arr) {
5+
const quad = matrix => {
6+
const length = matrix.length;
7+
const half = length / 2;
8+
const pass = matrix => matrix.every(row => row.every(v => v === matrix[0][0]));
9+
10+
if (pass(matrix)) return [matrix[0][0]];
11+
if (length <= 2) return matrix;
12+
13+
const startPoints = [
14+
[0, 0],
15+
[0, half],
16+
[half, 0],
17+
[half, half],
18+
];
19+
20+
return startPoints.map(([r, c]) => quad(matrix.slice(r, r + half).map(row => row.slice(c, c + half))));
21+
};
22+
return quad(arr)
23+
.flat(Infinity)
24+
.reduce((a, c) => (c === 0 ? [a[0] + 1, a[1]] : [a[0], a[1] + 1]), [0, 0]);
25+
}

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /