-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathboard.js
More file actions
34 lines (32 loc) · 853 Bytes
/
board.js
File metadata and controls
34 lines (32 loc) · 853 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
const board = [
[0, 1, 1, 1],
[1, 1, 1, 1],
[1, 1, 1, 1],
[0, 1, 1, 1],
];
const result = 9;
// 가장 큰 정사각형을 구해라.
function solution(board) {
const boardLength = board.length;
const columLength = board[0].length;
let len = 0;
for (let i = 1; i < boardLength; i++) {
for (let j = 1; j < columLength; j++) {
if (board[i][j] === 1) {
board[i][j] =
Math.min(board[i][j - 1], board[i - 1][j], board[i - 1][j - 1]) + 1; // 변의 값 구하는거
console.log(board[i][j], i, j);
if (board[i][j] > len) {
len = board[i][j];
console.log("len : ", len);
}
}
}
}
if (board.length === 1 && columLength === 1) {
if (board[0][0] === 1) return 1;
if (board[0][0] === 0) return 0;
}
return len * len;
}
console.log(solution(board));