-
Notifications
You must be signed in to change notification settings - Fork 0
/
Day110.cpp
48 lines (39 loc) · 1.13 KB
/
Day110.cpp
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
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
// Set Matrix Zeros
// https://www.interviewbit.com/problems/set-matrix-zeros/
void Solution::setZeroes(vector<vector<int> > &A) {
// Do not write main() function.
// Do not read input, instead use the arguments to the function.
// Do not print the output, instead return values as specified
// Still have a doubt. Checkout www.interviewbit.com/pages/sample_codes/ for more details
int m = A.size();
int n = A[0].size();
bool flag = false;
for(int i = 0; i < m; i++) {
for(int j = 0; j < n; j++) {
if(A[i][j] == 0) {
A[i][0] = 0;
if(j != 0) {
A[0][j] = 0;
} else {
flag = true;
}
}
}
}
for(int i = 1; i < m; i++) {
for(int j = 1; j < n; j++) {
if(A[i][0] == 0 || A[0][j] == 0)
A[i][j] = 0;
}
}
if(A[0][0] == 0) {
for(int i = 0; i < n; i++){
A[0][i] = 0;
}
}
if(flag) {
for(int i = 0; i < m; i++) {
A[i][0] = 0;
}
}
}