Created
May 25, 2018 16:21
-
-
Save jianminchen/d729e146e1268b88f0a9f6dd6094b52f to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Given a matrix consists of 0 and 1, find the distance of the nearest 0 for each cell. | |
The distance between two adjacent cells is 1. | |
Example 1: | |
Input: | |
0 0 0 | |
0 1 0 | |
0 0 0 | |
Output: | |
0 0 0 | |
0 1 0 | |
0 0 0 | |
Example 2: | |
Input: | |
0 0 0 | |
0 1 0 | |
1 1 1 | |
-1 -1 -1 | |
-1 0 -1 | |
-1 -1 | |
Output: | |
0 0 0 | |
0 1 0 | |
1 2 1 | |
keywords: | |
matrix, value only 0 and 1, | |
statement: the distance two adjacent cell is 1 | |
left, right, up or down , at most 4 adajcent cells | |
ask: find distance of nearest 0 for each cell | |
if cell value is 0, no change | |
if cell value is 1, | |
0 0 0 | |
0 1 0 | |
0 0 0 | |
0 0 0 | |
0 1 0 | |
1 2 1 <-- | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment