Skip to content

Commit

Permalink
LeetCode/73.cc
Browse files Browse the repository at this point in the history
  • Loading branch information
userr2232 committed Apr 10, 2022
1 parent 1181a73 commit fdfb4d4
Showing 1 changed file with 18 additions and 0 deletions.
18 changes: 18 additions & 0 deletions LeetCode/73.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
class Solution {
public:
void setZeroes(vector<vector<int>>& matrix) {
int m = matrix.size();
int n = matrix[0].size();
bool column0 = false;
for(int i = 0; i < m; ++i) for(int j = 0; j < n; ++j) if(matrix[i][j] == 0) {
matrix[i][0] = 0;
if(j == 0) column0 = true;
else matrix[0][j] = 0;
}
for (int i = m-1; i >= 0; --i) {
for (int j = 1; j < n; ++j)
if (matrix[i][0] == 0 || matrix[0][j] == 0) matrix[i][j] = 0;
if(column0) matrix[i][0] = 0;
}
}
};

0 comments on commit fdfb4d4

Please sign in to comment.