|
| 1 | +<h2><a href="https://leetcode.com/problems/01-matrix">01 Matrix</a></h2> <img src='https://img.shields.io/badge/Difficulty-Medium-orange' alt='Difficulty: Medium' /><hr><p>Given an <code>m x n</code> binary matrix <code>mat</code>, return <em>the distance of the nearest </em><code>0</code><em> for each cell</em>.</p> |
| 2 | + |
| 3 | +<p>The distance between two cells sharing a common edge is <code>1</code>.</p> |
| 4 | + |
| 5 | +<p> </p> |
| 6 | +<p><strong class="example">Example 1:</strong></p> |
| 7 | +<img alt="" src="https://assets.leetcode.com/uploads/2021/04/24/01-1-grid.jpg" style="width: 253px; height: 253px;" /> |
| 8 | +<pre> |
| 9 | +<strong>Input:</strong> mat = [[0,0,0],[0,1,0],[0,0,0]] |
| 10 | +<strong>Output:</strong> [[0,0,0],[0,1,0],[0,0,0]] |
| 11 | +</pre> |
| 12 | + |
| 13 | +<p><strong class="example">Example 2:</strong></p> |
| 14 | +<img alt="" src="https://assets.leetcode.com/uploads/2021/04/24/01-2-grid.jpg" style="width: 253px; height: 253px;" /> |
| 15 | +<pre> |
| 16 | +<strong>Input:</strong> mat = [[0,0,0],[0,1,0],[1,1,1]] |
| 17 | +<strong>Output:</strong> [[0,0,0],[0,1,0],[1,2,1]] |
| 18 | +</pre> |
| 19 | + |
| 20 | +<p> </p> |
| 21 | +<p><strong>Constraints:</strong></p> |
| 22 | + |
| 23 | +<ul> |
| 24 | + <li><code>m == mat.length</code></li> |
| 25 | + <li><code>n == mat[i].length</code></li> |
| 26 | + <li><code>1 <= m, n <= 10<sup>4</sup></code></li> |
| 27 | + <li><code>1 <= m * n <= 10<sup>4</sup></code></li> |
| 28 | + <li><code>mat[i][j]</code> is either <code>0</code> or <code>1</code>.</li> |
| 29 | + <li>There is at least one <code>0</code> in <code>mat</code>.</li> |
| 30 | +</ul> |
| 31 | + |
| 32 | +<p> </p> |
| 33 | +<p><strong>Note:</strong> This question is the same as 1765: <a href="https://leetcode.com/problems/map-of-highest-peak/description/" target="_blank">https://leetcode.com/problems/map-of-highest-peak/</a></p> |
0 commit comments