Skip to content

Commit 6a00823

Browse files
authored
Update minimum-operations-to-remove-adjacent-ones-in-matrix.cpp
1 parent af0e0cc commit 6a00823

File tree

1 file changed

+4
-4
lines changed

1 file changed

+4
-4
lines changed

C++/minimum-operations-to-remove-adjacent-ones-in-matrix.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -76,8 +76,8 @@ class Solution {
7676
if ((*lookup)[i][j]) {
7777
return;
7878
}
79-
auto get_id = [&grid, &ids](int i, int j) {
80-
const int x = size(grid[0]) * i + j, color = (i + j) % 2;
79+
auto get_id = [&grid, &ids](int i, int j, int color) {
80+
const int x = size(grid[0]) * i + j;
8181
if (!(*ids)[color].count(x)) {
8282
(*ids)[color][x] = size((*ids)[color]);
8383
}
@@ -96,8 +96,8 @@ class Solution {
9696
continue;
9797
}
9898
if (!color) {
99-
const int x = get_id(i, j);
100-
const int y = get_id(ni, nj);
99+
const int x = get_id(i, j, color);
100+
const int y = get_id(ni, nj, color ^ 1);
101101
adj->resize(size((*ids)[0]));
102102
(*adj)[x].emplace_back(y);
103103
}

0 commit comments

Comments
 (0)