-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathleet20423.cpp
More file actions
26 lines (26 loc) · 844 Bytes
/
leet20423.cpp
File metadata and controls
26 lines (26 loc) · 844 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
class Solution {
public:
void setZeroes(vector<vector<int>>& matrix) {
bool zeroinFirstCol = false;
for (int row = 0; row < matrix.size(); row++) {
if (matrix[row][0] == 0) zeroinFirstCol = true;
for (int col = 1; col < matrix[0].size(); col++) {
if (matrix[row][col] == 0) {
matrix[row][0] = 0;
matrix[0][col] = 0;
}
}
}
for (int row = matrix.size() - 1; row >= 0; row--) {
for (int col = matrix[0].size() - 1; col >= 1; col--) {
if (matrix[row][0] == 0 || matrix[0][col] == 0) {
matrix[row][col] = 0;
}
}
if (zeroinFirstCol) {
matrix[row][0] = 0;
}
}
}
};
//end program