Skip to content

Instantly share code, notes, and snippets.

@Se7soz
Last active May 12, 2017 19:54
Show Gist options
  • Select an option

  • Save Se7soz/8414317 to your computer and use it in GitHub Desktop.

Select an option

Save Se7soz/8414317 to your computer and use it in GitHub Desktop.
Read the How to prepare for an interview series at my blog: http://se7so.blogspot.com/2014/01/how-to-prepare-for-interview.html
void resetMtrx(vector<vector<int> >& mtrx) {
if(mtrx.size() == 0 || mtrx[0].size() == 0) return;
int rows[mtrx.size()], cols[mtrx[0].size()];
memset(rows, 1, sizeof rows);
memset(cols, 1, sizeof cols);
for(int i = 0; i < mtrx.size(); i++) {
for(int j = 0; j < mtrx[i].size(); j++) {
if(mtrx[i][j] == 0) {
rows[i] = cols[j] = 0;
}
}
}
for(int i = 0; i < mtrx.size(); i++)
for(int j = 0; j < mtrx[i].size(); j++)
if(rows[i] || cols[j]) mtrx[i][j] = '0';
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment