-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy path2128.cpp
More file actions
27 lines (27 loc) · 728 Bytes
/
2128.cpp
File metadata and controls
27 lines (27 loc) · 728 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
27
class Solution {
public:
bool removeOnes(vector<vector<int>>& grid) {
int m = grid.size();
int n = grid[0].size();
int first = 0;
for (int i = 1; i < m; ++i) {
// check first
bool flag = true;
for (int j = 0; j < n; ++j) {
if (grid[i][j] != grid[first][j]) {
flag = false;
break;
}
}
// check flip
if (!flag) {
for (int j = 0; j < n; ++j) {
if (grid[i][j] ^ grid[first][j] != 1) {
return false;
}
}
}
}
return true;
}
};