1
0
mirror of https://gitee.com/coder-xiaomo/leetcode-problemset synced 2025-01-10 18:48:13 +08:00
Code Issues Projects Releases Wiki Activity GitHub Gitee
leetcode-problemset/leetcode-cn/problem (Chinese)/统计全为 1 的正方形子矩阵 [count-square-submatrices-with-all-ones].html
2022-03-29 12:43:11 +08:00

45 lines
1.2 KiB
HTML
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<p>给你一个&nbsp;<code>m * n</code>&nbsp;的矩阵,矩阵中的元素不是 <code>0</code> 就是 <code>1</code>,请你统计并返回其中完全由 <code>1</code> 组成的 <strong>正方形</strong> 子矩阵的个数。</p>
<p>&nbsp;</p>
<p><strong>示例 1</strong></p>
<pre><strong>输入:</strong>matrix =
[
&nbsp; [0,1,1,1],
&nbsp; [1,1,1,1],
&nbsp; [0,1,1,1]
]
<strong>输出:</strong>15
<strong>解释:</strong>
边长为 1 的正方形有 <strong>10</strong> 个。
边长为 2 的正方形有 <strong>4</strong> 个。
边长为 3 的正方形有 <strong>1</strong> 个。
正方形的总数 = 10 + 4 + 1 = <strong>15</strong>.
</pre>
<p><strong>示例 2</strong></p>
<pre><strong>输入:</strong>matrix =
[
[1,0,1],
[1,1,0],
[1,1,0]
]
<strong>输出:</strong>7
<strong>解释:</strong>
边长为 1 的正方形有 <strong>6</strong> 个。
边长为 2 的正方形有 <strong>1</strong> 个。
正方形的总数 = 6 + 1 = <strong>7</strong>.
</pre>
<p>&nbsp;</p>
<p><strong>提示:</strong></p>
<ul>
<li><code>1 &lt;= arr.length&nbsp;&lt;= 300</code></li>
<li><code>1 &lt;= arr[0].length&nbsp;&lt;= 300</code></li>
<li><code>0 &lt;= arr[i][j] &lt;= 1</code></li>
</ul>