8000 Submit Maximal Square solution · bezzad/LeetCode@88aae75 · GitHub
[go: up one dir, main page]

Skip to content

Commit 88aae75

Browse files
committed
Submit Maximal Square solution
1 parent cd5104c commit 88aae75

File tree

1 file changed

+7
-6
lines changed

1 file changed

+7
-6
lines changed

221. Maximal Square/221. Maximal Square.js

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,19 +10,20 @@
1010
var maximalSquare = function (matrix) {
1111
let max = 0;
1212
let deepKeeper = new Array(matrix.length).fill().map(() => new Array(matrix[0].length).fill(-1));
13-
// matrix.forEach((v) => v.push("0")); // right zero padding
14-
// matrix.push(new Array(matrix[0].length).fill("0")); // bottom zero padding
1513

1614
for (let i = 0; i < matrix.length; i++) {
1715
for (let j = 0; j < matrix[i].length; j++) {
1816
if (matrix[i][j] == "1") {
1917
let currentLen = getDeep(matrix, i, j, deepKeeper) + 1;
20-
max = Math.max(max, currentLen);
18+
max = Math.max(max, currentLen);
19+
}
20+
else {
21+
deepKeeper[i][j] = 0;
2122
}
2223
}
2324
}
2425

25-
return max;
26+
return max*max;
2627
};
2728

2829
function getDeep(matrix, i, j, deepKeeper) {
@@ -37,7 +38,7 @@ function getDeep(matrix, i, j, deepKeeper) {
3738
for (let i = 0; i < neighbors.length; i++) {
3839
min = Math.min(min, getDeep(matrix, neighbors[i][0], neighbors[i][1], deepKeeper));
3940
}
40-
deepKeeper[i, j] = min + 1;
41+
deepKeeper[i][j] = min + 1;
4142
}
4243

4344
return deepKeeper[i][j];
@@ -52,7 +53,7 @@ function hasNeighbors(matrix, i, j) {
5253

5354
if (matrix.length > i + 1 && matrix[i].length > j + 1) {
5455
for (let i = 0; i < neighbors.length; i++) {
55-
if (matrix[neighbors[i][0], neighbors[i][1]] != "1") {
56+
if (matrix[neighbors[i][0]][neighbors[i][1]] != "1") {
5657
return null;
5758
}
5859
}

0 commit comments

Comments
 (0)
0