Skip to content

Commit 5777723

Browse files
committed
Cutting n^2 / 심화
1 parent adac814 commit 5777723

File tree

1 file changed

+11
-0
lines changed

1 file changed

+11
-0
lines changed

bona1122/Array/Cutting_n^2.js

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
// 핵심
2+
// 1. 1차원 배열을 인덱스를 이용해서 (n,n) 행렬로 변환하는 관점
3+
// 2. i = 1,2, ..., n 에 대해 1행1열부터 i행i열까지의 영역 내의 빈 칸을 숫자 i로 채우는 것이 Math.max(row, col)인 규칙을 갖는다는 것
4+
function solution(n, left, right) {
5+
return Array.from({ length: right - left + 1 }, (_, idx) => {
6+
const i = left + idx;
7+
const row = Math.floor(i / n);
8+
const col = i % n;
9+
return Math.max(row, col) + 1;
10+
});
11+
}

0 commit comments

Comments
 (0)