题目
解题:动态规划
与 LeetCode221 最大正方形 几乎一样。
因为是以 [i, j] 为右下角,此前并未统计过,因而不会重复。以下图为例,如果新获得一个边长为4的正方形,新加入的是如下这4个正方形。
// javascript
var countSquares = function(matrix) {
let squaresNum = 0;
if (matrix === null || matrix.length === 0 || matrix[0].length === 0) return squaresNum;
const rows = matrix.length, columns = matrix[0].length;
const dp = new Array(rows