Given an m×n binary matrix, mat, find the distance from each cell to the nearest 0. The distance between two adjacent cells is 1. Cells to the left, right, above, and below the current cell will be considered adjacent.
Constraints:
1≤mat.row , mat.col≤50
1≤mat.row * mat.col≤2500
mat[i][j] ...
⋮
Tap here to switch tabs
Problem
Ask
Submissions
Solution
Solution: 01 Matrix
Statement▼
Given an m×n binary matrix, mat, find the distance from each cell to the nearest 0. The distance between two adjacent cells is 1. Cells to the left, right, above, and below the current cell will be considered adjacent.