mirror of
https://gitee.com/coder-xiaomo/leetcode-problemset
synced 2025-01-11 02:58:13 +08:00
45 lines
1.1 KiB
HTML
45 lines
1.1 KiB
HTML
<p>Given a <code>m * n</code> matrix of ones and zeros, return how many <strong>square</strong> submatrices have all ones.</p>
|
|
|
|
<p> </p>
|
|
<p><strong>Example 1:</strong></p>
|
|
|
|
<pre>
|
|
<strong>Input:</strong> matrix =
|
|
[
|
|
[0,1,1,1],
|
|
[1,1,1,1],
|
|
[0,1,1,1]
|
|
]
|
|
<strong>Output:</strong> 15
|
|
<strong>Explanation:</strong>
|
|
There are <strong>10</strong> squares of side 1.
|
|
There are <strong>4</strong> squares of side 2.
|
|
There is <strong>1</strong> square of side 3.
|
|
Total number of squares = 10 + 4 + 1 = <strong>15</strong>.
|
|
</pre>
|
|
|
|
<p><strong>Example 2:</strong></p>
|
|
|
|
<pre>
|
|
<strong>Input:</strong> matrix =
|
|
[
|
|
[1,0,1],
|
|
[1,1,0],
|
|
[1,1,0]
|
|
]
|
|
<strong>Output:</strong> 7
|
|
<strong>Explanation:</strong>
|
|
There are <b>6</b> squares of side 1.
|
|
There is <strong>1</strong> square of side 2.
|
|
Total number of squares = 6 + 1 = <b>7</b>.
|
|
</pre>
|
|
|
|
<p> </p>
|
|
<p><strong>Constraints:</strong></p>
|
|
|
|
<ul>
|
|
<li><code>1 <= arr.length <= 300</code></li>
|
|
<li><code>1 <= arr[0].length <= 300</code></li>
|
|
<li><code>0 <= arr[i][j] <= 1</code></li>
|
|
</ul>
|