class Solution {
public:
void setZeroes(vector<vector<int> > &matrix) {
int m = matrix.size();
int n = matrix[0].size();
bool line = false;
bool hine = false;
for (int i=0;i!=m;i++)
for (int j=0;j!=n;j++)
if (matrix[i][j] == 0) {
matrix[0][j] = 0;
matrix[i][0] = 0;
if (i == 0)
line = true;
if (j == 0)
hine = true;
}
for (int i=m1;i!=0;i)
if (matrix[i][0] == 0){
for(int j=0;j!=n;j++)
matrix[i][j] = 0;
}
for(int j=n1;j!=0;j)
if (matrix[0][j] == 0)
for(int k=0;k!=m;k++)
matrix[k][j] = 0;
if (matrix[0][0] == 0){
if (hine)
for (int i=0;i!=m;i++)
matrix[i][0] = 0;
if (line)
for (int j=0;j!=n;j++)
matrix[0][j] = 0;
}
}
};
A tricky solution, and I wonder can this satisfy the "const place"?


Thanks for your post. However it would be better to share solution with correct code format and elaborated thoughts. Please read the Discuss FAQ for more info. Take a look at good sharing example

Actually both first row and first column are not set till the end. If matrix[0][0] == 0, we don't need to check it because first row and first column should be set to 0, and hine and line are always true. If matrix[0][0] == 1, we need help from the booleans. So we can cancel the if block and just check whether hine or line is true.