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

48 lines
1.6 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 x n</code>&nbsp;的二进制矩阵&nbsp;<code>mat</code>&nbsp;,请你返回有多少个&nbsp;<strong>子矩形</strong>&nbsp;的元素全部都是 1 。</p>
<p>&nbsp;</p>
<p><strong>示例 1</strong></p>
<p><img src="https://assets.leetcode.com/uploads/2021/10/27/ones1-grid.jpg" /></p>
<pre>
<strong>输入:</strong>mat = [[1,0,1],[1,1,0],[1,1,0]]
<strong>输出:</strong>13
<strong>解释:
</strong><strong>6</strong>&nbsp;个 1x1 的矩形。
<strong>2</strong> 个 1x2 的矩形。
<strong>3</strong> 个 2x1 的矩形。
<strong>1</strong> 个 2x2 的矩形。
<strong>1</strong> 个 3x1 的矩形。
矩形数目总共 = 6 + 2 + 3 + 1 + 1 = <strong>13</strong>&nbsp;
</pre>
<p><strong>示例 2</strong></p>
<p><img src="https://assets.leetcode.com/uploads/2021/10/27/ones2-grid.jpg" /></p>
<pre>
<strong>输入:</strong>mat = [[0,1,1,0],[0,1,1,1],[1,1,1,0]]
<strong>输出:</strong>24
<strong>解释:</strong>
<strong>8</strong> 个 1x1 的子矩形。
<strong>5</strong> 个 1x2 的子矩形。
<strong>2</strong> 个 1x3 的子矩形。
<strong>4</strong> 个 2x1 的子矩形。
<strong>2</strong> 个 2x2 的子矩形。
<strong>2</strong> 个 3x1 的子矩形。
<strong>1</strong> 个 3x2 的子矩形。
矩形数目总共 = 8 + 5 + 2 + 4 + 2 + 2 + 1 = <strong>24</strong><strong></strong>
</pre>
<p>&nbsp;</p>
<p><strong>提示:</strong></p>
<ul>
<li><code>1 &lt;= m, n &lt;= 150</code></li>
<li><code>mat[i][j]</code>&nbsp;仅包含&nbsp;<code>0</code>&nbsp;&nbsp;<code>1</code></li>
</ul>