We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent adac814 commit 5777723Copy full SHA for 5777723
bona1122/Array/Cutting_n^2.js
@@ -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