-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path0073-set-matrix-zeroes.cpp
More file actions
46 lines (44 loc) · 1.04 KB
/
0073-set-matrix-zeroes.cpp
File metadata and controls
46 lines (44 loc) · 1.04 KB
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
#include <vector>
#include <iostream>
using namespace std;
class Solution
{
public:
void setZeroes(vector<vector<int>> &matrix)
{
int count_rows = matrix.size();
if (count_rows < 1)
return;
int count_col = matrix[0].size();
vector<bool> zero_cols(count_col, false);
vector<bool> zero_rows(count_rows, false);
for (int i = 0; i < count_rows; i++)
{
for (int j = 0; j < count_col; j++)
{
if (matrix[i][j] == 0)
{
zero_rows[i] = true;
zero_cols[j] = true;
}
}
}
for (int i = 0; i < count_rows; i++)
{
for (int j = 0; j < count_col; j++)
{
if (zero_rows[i] || zero_cols[j])
{
matrix[i][j] = 0;
}
}
}
return;
}
};
int main()
{
vector<int> i;
vector<vector<int>> matrix;
(new Solution())->setZeroes(matrix);
}