mirror of
				https://gitee.com/coder-xiaomo/leetcode-problemset
				synced 2025-11-04 19:53:12 +08:00 
			
		
		
		
	
		
			
				
	
	
		
			48 lines
		
	
	
		
			1.6 KiB
		
	
	
	
		
			HTML
		
	
	
	
	
	
			
		
		
	
	
			48 lines
		
	
	
		
			1.6 KiB
		
	
	
	
		
			HTML
		
	
	
	
	
	
<p>给你一个 <code>m x n</code> 的二进制矩阵 <code>mat</code> ,请你返回有多少个 <strong>子矩形</strong> 的元素全部都是 1 。</p>
 | 
						||
 | 
						||
<p> </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> 个 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> 。
 | 
						||
</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> </p>
 | 
						||
 | 
						||
<p><strong>提示:</strong></p>
 | 
						||
 | 
						||
<ul>
 | 
						||
	<li><code>1 <= m, n <= 150</code></li>
 | 
						||
	<li><code>mat[i][j]</code> 仅包含 <code>0</code> 或 <code>1</code></li>
 | 
						||
</ul>
 |