Given a m x n matrix, if an element is 0, set its entire row and column to 0. Do it in place.
class Solution {
public:
void setZeroes(vector<vector<int> > &matrix) {
// Start typing your C/C++ solution below
// DO NOT write int main() function
int row = matrix.size();
int col = matrix[0].size();
vector<bool> rowVec;
rowVec.resize(row, false);
vector<bool> colVec;
colVec.resize(col, false);
for (int i = 0; i < row; ++i)
{
for (int j = 0; j < col; ++j)
{
if (matrix[i][j] == 0)
{
rowVec[i] = true;
colVec[j] = true;
}
}
}
for (int i = 0; i < row; ++i)
{
if (rowVec[i])
{
for (int j = 0; j < col; ++j)
{
matrix[i][j] = 0;
}
}
}
for (int j = 0; j < col; ++j)
{
if (colVec[j])
{
for (int i = 0; i < row; ++i)
{
matrix[i][j] = 0;
}
}
}
}
};