88ms c++


  • 0
    B
    class Solution {
    public:
        void setZeroes(vector< vector<int> >& matrix) {
            int row = matrix.size(), col = matrix[0].size();
            bool col0=false;
            for(int i=0;i<row;i++)
            {
                if (matrix[i][0]==0) col0=true;
                for(int j=1;j<col;j++)
                {
                    if (matrix[i][j]==0)
                    {
                        matrix[0][j]=0;
                        matrix[i][0]=0;
                    }
                }
            }
            for(int i=row-1;i>=0;i--)
            {
                for(int j=1;j<col;j++)
                {
                    if (matrix[i][0]==0 || matrix[0][j]==0)
                        matrix[i][j] = 0;
                }
                if (col0) matrix[i][0]=0;
            }
        }
    };
    

Log in to reply
 

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