图论14(Leetcode542.01矩阵)

补0917

答案:

class Solution {
    public int[][] updateMatrix(int[][] mat) {
        Queue zeros = new LinkedList<>();
        int[][] res = new int[mat.length][mat[0].length];
        int count = 0;
        int num = mat.length * mat[0].length;
        for(int i=0;i=0&&mat[zerox+x][zeroy-y]==1){
                        res[zerox+x][zeroy-y] = step;
                        mat[zerox+x][zeroy-y] = -1;
                        count++;
                    }
                    if(zerox-x>=0&&zeroy+y=0&&zeroy-y>=0&&mat[zerox-x][zeroy-y]==1){
                        res[zerox-x][zeroy-y] = step;
                        mat[zerox-x][zeroy-y] = -1;
                        count++;
                    }
                }
            }
            step++;
        }
        return res;
    }
}

你可能感兴趣的:(图论,矩阵,算法)