将矩阵中值为0的元素所在的行和列设置为0, in-place O(1)space O(mn) time

Given a m x n matrix, if an element is 0, set its entire row and column to 0. Do it in place.

Follow up:

Did you use extra space?
A straight forward solution using O(mn) space is probably a bad idea.
A simple improvement uses O(m + n) space, but still not the best solution.
Could you devise a constant space solution?

public class Solution {
    public void setZeroes(int[][] matrix) {
        
        int m=matrix.length;
        if(m==0)
            return;
        int n=matrix[0].length;
        if(n==0)
            return;
        boolean preZeros=false;
        boolean curZeros=false;
        for(int i=0;i0)
            {
                for(int j=0;j



你可能感兴趣的:(算法,Java)