Simple C++ solution beats 99.51%.


  • 0
    A
    class Solution {
    public:
        void setZeroes(vector<vector<int>>& matrix) {
            vector<bool> row_zero(matrix.size(),false);
            vector<bool> line_zero(matrix[0].size(),false);
            int i, j;
            for (i=0;i<row_zero.size();i++) {
                for (j=0;j<line_zero.size();j++) {
                    if (matrix[i][j]==0) {
                        row_zero[i]=true;
                        line_zero[j]=true;
                    }
                }
            }
            for (i=0;i<row_zero.size();i++) {
                for (j=0;j<line_zero.size();j++) {
                    if (row_zero[i]) matrix[i][j]=0;
                    else if (line_zero[j]) matrix[i][j]=0;
                }
            }
        }
    };

Log in to reply
 

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