给予一个矩阵,矩阵有1有0,计算每一个1到0需要走几步,只能走上下左右. 解法一: 利用dp,从左上角遍历一遍,再从右下角遍历一遍,dp存储当前位置到0的最短距离. 十分粗心的搞错了col和row,改了半天………… Runtime: 132 ms, faster than 98.88% of C++ online submissions for 01 Matrix. class Solution { public: vector<vector<int>> updateMatrix(…
[LeetCode]01 Matrix 解题报告 标签(空格分隔): LeetCode 题目地址:https://leetcode.com/problems/01-matrix/#/description 题目描述: 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:…
01 Matrix 题解 原创文章,拒绝转载 题目来源:https://leetcode.com/problems/01-matrix/description/ Description 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…
class Solution { public: vector<vector<int>> res; int m, n; vector<vector<int>> updateMatrix(vector<vector<int>>& matrix) { m = matrix.size(); ) return res; n = matrix[].size(); ) return res; res = vector<vector&…