Skip to content

Commit e23cd5d

Browse files
authored
[PGS] 77485 행렬 테두리 회전하기 (Lv.2)
1 parent 5d6a925 commit e23cd5d

File tree

1 file changed

+55
-0
lines changed

1 file changed

+55
-0
lines changed

박예진/0주차/구현/77485.js

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
function solution(rows, columns, queries) {
2+
var answer = [];
3+
4+
let arr = Array.from({length: rows + 1}, () => []);
5+
6+
// 초기 세팅
7+
let cnt = 1;
8+
for(let i = 1; i <= rows; i++) {
9+
for(let j = 1; j <= columns; j++){
10+
arr[i][j] = cnt;
11+
cnt++;
12+
}
13+
}
14+
15+
// 시계방향
16+
for(const query of queries) {
17+
let x1 = query[0];
18+
let y1 = query[1];
19+
let x2 = query[2];
20+
let y2 = query[3];
21+
22+
let res = 1e9;
23+
let temp = arr[x1][y1];
24+
25+
// 아래 -> 위
26+
for(let i = x1; i < x2; i++) {
27+
arr[i][y1] = arr[i + 1][y1];
28+
res = Math.min(res, arr[i][y1]);
29+
}
30+
// 오 -> 왼
31+
for(let j = y1; j < y2; j++){
32+
arr[x2][j] = arr[x2][j + 1];
33+
res = Math.min(res, arr[x2][j]);
34+
}
35+
// 위 -> 아래
36+
for(let i = x2; i > x1; i--) {
37+
arr[i][y2] = arr[i - 1][y2];
38+
res = Math.min(res, arr[i][y2]);
39+
}
40+
// 왼 -> 오
41+
for(let j = y2; j > y1; j--){
42+
arr[x1][j] = arr[x1][j - 1];
43+
res = Math.min(res, arr[x1][j]);
44+
}
45+
arr[x1][y1 + 1] = temp;
46+
res = Math.min(res, arr[x1][y1 + 1]);
47+
48+
answer.push(res);
49+
}
50+
51+
52+
53+
54+
return answer;
55+
}

0 commit comments

Comments
 (0)