mirror of
				https://gitee.com/coder-xiaomo/leetcode-problemset
				synced 2025-11-04 11:43:12 +08:00 
			
		
		
		
	国外版
This commit is contained in:
		
							
								
								
									
										40
									
								
								算法题(国外版)/max-increase-to-keep-city-skyline.html
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										40
									
								
								算法题(国外版)/max-increase-to-keep-city-skyline.html
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,40 @@
 | 
			
		||||
<p>There is a city composed of <code>n x n</code> blocks, where each block contains a single building shaped like a vertical square prism. You are given a <strong>0-indexed</strong> <code>n x n</code> integer matrix <code>grid</code> where <code>grid[r][c]</code> represents the <strong>height</strong> of the building located in the block at row <code>r</code> and column <code>c</code>.</p>
 | 
			
		||||
 | 
			
		||||
<p>A city's <strong>skyline</strong> is the the outer contour formed by all the building when viewing the side of the city from a distance. The <strong>skyline</strong> from each cardinal direction north, east, south, and west may be different.</p>
 | 
			
		||||
 | 
			
		||||
<p>We are allowed to increase the height of <strong>any number of buildings by any amount</strong> (the amount can be different per building). The height of a <code>0</code>-height building can also be increased. However, increasing the height of a building should <strong>not</strong> affect the city's <strong>skyline</strong> from any cardinal direction.</p>
 | 
			
		||||
 | 
			
		||||
<p>Return <em>the <strong>maximum total sum</strong> that the height of the buildings can be increased by <strong>without</strong> changing the city's <strong>skyline</strong> from any cardinal direction</em>.</p>
 | 
			
		||||
 | 
			
		||||
<p> </p>
 | 
			
		||||
<p><strong>Example 1:</strong></p>
 | 
			
		||||
<img alt="" src="https://assets.leetcode.com/uploads/2021/06/21/807-ex1.png" style="width: 700px; height: 603px;" />
 | 
			
		||||
<pre>
 | 
			
		||||
<strong>Input:</strong> grid = [[3,0,8,4],[2,4,5,7],[9,2,6,3],[0,3,1,0]]
 | 
			
		||||
<strong>Output:</strong> 35
 | 
			
		||||
<strong>Explanation:</strong> The building heights are shown in the center of the above image.
 | 
			
		||||
The skylines when viewed from each cardinal direction are drawn in red.
 | 
			
		||||
The grid after increasing the height of buildings without affecting skylines is:
 | 
			
		||||
gridNew = [ [8, 4, 8, 7],
 | 
			
		||||
            [7, 4, 7, 7],
 | 
			
		||||
            [9, 4, 8, 7],
 | 
			
		||||
            [3, 3, 3, 3] ]
 | 
			
		||||
</pre>
 | 
			
		||||
 | 
			
		||||
<p><strong>Example 2:</strong></p>
 | 
			
		||||
 | 
			
		||||
<pre>
 | 
			
		||||
<strong>Input:</strong> grid = [[0,0,0],[0,0,0],[0,0,0]]
 | 
			
		||||
<strong>Output:</strong> 0
 | 
			
		||||
<strong>Explanation:</strong> Increasing the height of any building will result in the skyline changing.
 | 
			
		||||
</pre>
 | 
			
		||||
 | 
			
		||||
<p> </p>
 | 
			
		||||
<p><strong>Constraints:</strong></p>
 | 
			
		||||
 | 
			
		||||
<ul>
 | 
			
		||||
	<li><code>n == grid.length</code></li>
 | 
			
		||||
	<li><code>n == grid[r].length</code></li>
 | 
			
		||||
	<li><code>2 <= n <= 50</code></li>
 | 
			
		||||
	<li><code>0 <= grid[r][c] <= 100</code></li>
 | 
			
		||||
</ul>
 | 
			
		||||
		Reference in New Issue
	
	Block a user