Class Solution
java.lang.Object
g1701_1800.s1765_map_of_highest_peak.Solution
1765 - Map of Highest Peak.<p>Medium</p>
<p>You are given an integer matrix <code>isWater</code> of size <code>m x n</code> that represents a map of <strong>land</strong> and <strong>water</strong> cells.</p>
<ul>
<li>If <code>isWater[i][j] == 0</code>, cell <code>(i, j)</code> is a <strong>land</strong> cell.</li>
<li>If <code>isWater[i][j] == 1</code>, cell <code>(i, j)</code> is a <strong>water</strong> cell.</li>
</ul>
<p>You must assign each cell a height in a way that follows these rules:</p>
<ul>
<li>The height of each cell must be non-negative.</li>
<li>If the cell is a <strong>water</strong> cell, its height must be <code>0</code>.</li>
<li>Any two adjacent cells must have an absolute height difference of <strong>at most</strong> <code>1</code>. A cell is adjacent to another cell if the former is directly north, east, south, or west of the latter (i.e., their sides are touching).</li>
</ul>
<p>Find an assignment of heights such that the maximum height in the matrix is <strong>maximized</strong>.</p>
<p>Return <em>an integer matrix</em> <code>height</code> <em>of size</em> <code>m x n</code> <em>where</em> <code>height[i][j]</code> <em>is cell</em> <code>(i, j)</code><em>’s height. If there are multiple solutions, return <strong>any</strong> of them</em>.</p>
<p><strong>Example 1:</strong></p>
<p><strong><img src="https://assets.leetcode.com/uploads/2021/01/10/screenshot-2021-01-11-at-82045-am.png" alt="" /></strong></p>
<p><strong>Input:</strong> isWater = [[0,1],[0,0]]</p>
<p><strong>Output:</strong> [[1,0],[2,1]]</p>
<p><strong>Explanation:</strong> The image shows the assigned heights of each cell. The blue cell is the water cell, and the green cells are the land cells.</p>
<p><strong>Example 2:</strong></p>
<p><strong><img src="https://assets.leetcode.com/uploads/2021/01/10/screenshot-2021-01-11-at-82050-am.png" alt="" /></strong></p>
<p><strong>Input:</strong> isWater = [[0,0,1],[1,0,0],[0,0,0]]</p>
<p><strong>Output:</strong> [[1,1,0],[0,1,1],[1,2,2]]</p>
<p><strong>Explanation:</strong> A height of 2 is the maximum possible height of any assignment. Any height assignment that has a maximum height of 2 while still meeting the rules will also be accepted.</p>
<p><strong>Constraints:</strong></p>
<ul>
<li><code>m == isWater.length</code></li>
<li><code>n == isWater[i].length</code></li>
<li><code>1 <= m, n <= 1000</code></li>
<li><code>isWater[i][j]</code> is <code>0</code> or <code>1</code>.</li>
<li>There is at least <strong>one</strong> water cell.</li>
</ul>
-
Constructor Summary
Constructors -
Method Summary
-
Constructor Details
-
Solution
public Solution()
-
-
Method Details
-
highestPeak
public int[][] highestPeak(int[][] isWater)
-