Skip to content

Commit b45e5b4

Browse files
author
Shuo
committed
A: new
1 parent 1e14d9e commit b45e5b4

File tree

1 file changed

+18
-26
lines changed
  • problems/as-far-from-land-as-possible

1 file changed

+18
-26
lines changed

Diff for: problems/as-far-from-land-as-possible/README.md

+18-26
Original file line numberDiff line numberDiff line change
@@ -11,44 +11,36 @@
1111

1212
## [1162. As Far from Land as Possible (Medium)](https://leetcode.com/problems/as-far-from-land-as-possible "地图分析")
1313

14-
<p>Given an N x N <code>grid</code>&nbsp;containing only values <code>0</code> and <code>1</code>, where&nbsp;<code>0</code> represents water&nbsp;and <code>1</code> represents land, find a water cell such that its distance to the nearest land cell is maximized and return the distance.</p>
14+
<p>Given an <code>n x n</code> <code>grid</code>&nbsp;containing only values <code>0</code> and <code>1</code>, where&nbsp;<code>0</code> represents water&nbsp;and <code>1</code> represents land, find a water cell such that its distance to the nearest land cell is maximized, and return the distance.&nbsp;If no land or water exists in the grid, return <code>-1</code>.</p>
1515

16-
<p>The distance used in this problem is the <em>Manhattan distance</em>:&nbsp;the distance between two cells <code>(x0, y0)</code> and <code>(x1, y1)</code> is <code>|x0 - x1| + |y0 - y1|</code>.</p>
17-
18-
<p>If no land or water exists in the grid, return <code>-1</code>.</p>
16+
<p>The distance used in this problem is the Manhattan distance:&nbsp;the distance between two cells <code>(x0, y0)</code> and <code>(x1, y1)</code> is <code>|x0 - x1| + |y0 - y1|</code>.</p>
1917

2018
<p>&nbsp;</p>
21-
2219
<p><strong>Example 1:</strong></p>
23-
24-
<p><strong><img alt="" src="https://assets.leetcode.com/uploads/2019/05/03/1336_ex1.JPG" style="width: 185px; height: 87px;" /></strong></p>
25-
20+
<img alt="" src="https://assets.leetcode.com/uploads/2019/05/03/1336_ex1.JPG" style="width: 185px; height: 87px;" />
2621
<pre>
27-
<strong>Input: </strong><span id="example-input-1-1">[[1,0,1],[0,0,0],[1,0,1]]</span>
28-
<strong>Output: </strong><span id="example-output-1">2</span>
29-
<strong>Explanation: </strong>
30-
The cell (1, 1) is as far as possible from all the land with distance 2.
22+
<strong>Input:</strong> grid = [[1,0,1],[0,0,0],[1,0,1]]
23+
<strong>Output:</strong> 2
24+
<strong>Explanation:</strong> The cell (1, 1) is as far as possible from all the land with distance 2.
3125
</pre>
3226

3327
<p><strong>Example 2:</strong></p>
34-
35-
<p><strong><img alt="" src="https://assets.leetcode.com/uploads/2019/05/03/1336_ex2.JPG" style="width: 184px; height: 87px;" /></strong></p>
36-
28+
<img alt="" src="https://assets.leetcode.com/uploads/2019/05/03/1336_ex2.JPG" style="width: 184px; height: 87px;" />
3729
<pre>
38-
<strong>Input: </strong><span id="example-input-2-1">[[1,0,0],[0,0,0],[0,0,0]]</span>
39-
<strong>Output: </strong><span id="example-output-2">4</span>
40-
<strong>Explanation: </strong>
41-
The cell (2, 2) is as far as possible from all the land with distance 4.
30+
<strong>Input:</strong> grid = [[1,0,0],[0,0,0],[0,0,0]]
31+
<strong>Output:</strong> 4
32+
<strong>Explanation:</strong> The cell (2, 2) is as far as possible from all the land with distance 4.
4233
</pre>
4334

4435
<p>&nbsp;</p>
45-
46-
<p><span><strong>Note:</strong></span></p>
47-
48-
<ol>
49-
<li><span><code>1 &lt;= grid.length == grid[0].length&nbsp;&lt;= 100</code></span></li>
50-
<li><span><code>grid[i][j]</code>&nbsp;is <code>0</code> or <code>1</code></span></li>
51-
</ol>
36+
<p><strong>Constraints:</strong></p>
37+
38+
<ul>
39+
<li><code>n == grid.length</code></li>
40+
<li><code>n == grid[i].length</code></li>
41+
<li><code>1 &lt;= n&nbsp;&lt;= 100</code></li>
42+
<li><code>grid[i][j]</code>&nbsp;is <code>0</code> or <code>1</code></li>
43+
</ul>
5244

5345
### Related Topics
5446
[[Breadth-first Search](../../tag/breadth-first-search/README.md)]

0 commit comments

Comments
 (0)