A not really guaranteed solution, but very probable to be accepted


  • 0
    S

    public class Solution {
    public void setZeroes(int[][] matrix) {
    int i,j , k;
    int m =matrix.length;

        if (m == 0)
            return;
        int n = matrix[0].length;
        
        if(n == 0)
            return;
            
        for (i =0;i<m;i++) {
            for (j=0;j<n;j++) {
                if(matrix[i][j] == 0)
                    matrix[i][j] = 0xffffff;
            }
        }
        
        for (i =0;i<m;i++) {
            for (j=0;j<n;j++) {
                if(matrix[i][j] == 0xffffff) {
                    for(k = 0;k < m;k++) {
                        if(matrix[k][j] == 0xffffff)
                            continue;
                        else
                            matrix[k][j] = 0;
                        
                    }
                    for(k = 0;k < n;k++){
                        if(matrix[i][k] == 0xffffff)
                            continue;
                        else
                            matrix[i][k] = 0;
                    }
                    matrix[i][j] = 0;
                }
                    
            }
        }
        
        return;
    }
    

    }


Log in to reply
 

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.