73. Set Matrix Zeroes

 class Solution {

public:

    

    void setZeroes(vector<vector<int>>& matrix) {

        

        map<int,int>r,c;

        

        for(int i=0;i<matrix.size();i++){

            for(int j=0; j<matrix[i].size();j++){

                if(matrix[i][j]==0){

                    r[i]=1;

                    c[j]=1;

                }

            }

        }

        

        for(int i=0;i<matrix.size();i++){

            for(int j=0; j<matrix[i].size();j++){

                if(r[i]==1 || c[j]==1){

                    matrix[i][j]=0;                   

                }

            }

        }

        

    }

};

Comments

Popular posts from this blog

1431. Kids With the Greatest Number of Candies

125. Valid Palindrome

771. Jewels and Stones