forked from illuz/leetcode
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathAC_array_n+m.cpp
39 lines (33 loc) · 888 Bytes
/
AC_array_n+m.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
/*
* Author: illuz <iilluzen[at]gmail.com>
* File: AC_array_n+m.cpp
* Create Date: 2014-12-28 13:55:57
* Descripton: use array, the space is O(n+m)
*/
#include <bits/stdc++.h>
using namespace std;
const int N = 0;
class Solution {
public:
void setZeroes(vector<vector<int> > &matrix) {
if (matrix.empty() || matrix[0].empty())
return;
int n = matrix.size();
int m = matrix[0].size();
vector<int> row(n);
vector<int> col(m);
for (int i = 0; i < n; i++)
for (int j = 0; j < m; j++)
if (!matrix[i][j]) {
row[i] = 1;
col[j] = 1;
}
for (int i = 0; i < n; i++)
for (int j = 0; j < m; j++)
if (row[i] || col[j])
matrix[i][j] = 0;
}
};
int main() {
return 0;
}