Maximal Square LeetCode solution in JavaScript

1
var maximalSquare = function (matrix) {
2
let max = 0;
3
const height = matrix.length - 1;
4
const width = matrix[0].length - 1;
5
for (let i = height; i >= 0; i--) {
6
for (let j = width; j >= 0; j--) {
7
const right = j < width ? Number(matrix[i][j + 1]) : 0;
8
const diag = i < height && j < width ? Number(matrix[i + 1][j + 1]) : 0;
9
const bottom = i < height ? Number(matrix[i + 1][j]) : 0;
10
matrix[i][j] =
11
matrix[i][j] === "0" ? 0 : Math.min(right, diag, bottom) + 1;
12
max = Math.max(max, matrix[i][j] * matrix[i][j]);
13
}
14
}
15
return max;
16
};

0

WPM •0 •0

100%

ACC •0 •0

0s

TIME •0