Skip to content

Commit 30adee9

Browse files
authored
Update minimum-number-of-visited-cells-in-a-grid.cpp
1 parent e40677d commit 30adee9

File tree

1 file changed

+12
-12
lines changed

1 file changed

+12
-12
lines changed

C++/minimum-number-of-visited-cells-in-a-grid.cpp

+12-12
Original file line numberDiff line numberDiff line change
@@ -89,12 +89,12 @@ class Solution2 {
8989
public:
9090
int minimumVisitedCells(vector<vector<int>>& grid) {
9191
const int m = size(grid), n = size(grid[0]);
92-
vector<set<int>> sl1(m);
93-
vector<set<int>> sl2(n);
92+
vector<set<int>> bst1(m);
93+
vector<set<int>> bst2(n);
9494
for (int i = 0; i < m; ++i) {
9595
for (int j = 0; j < n; ++j) {
96-
sl1[i].emplace(j);
97-
sl2[j].emplace(i);
96+
bst1[i].emplace(j);
97+
bst2[j].emplace(i);
9898
}
9999
}
100100
int d = 1, i = 0, j = 0;
@@ -105,17 +105,17 @@ class Solution2 {
105105
if (i == m - 1 && j == n - 1) {
106106
return d;
107107
}
108-
for (auto it = sl1[i].lower_bound(j + 1);
109-
it != end(sl1[i]) && *it <= j + grid[i][j];
110-
it = sl1[i].erase(it)) {
108+
for (auto it = bst1[i].lower_bound(j + 1);
109+
it != end(bst1[i]) && *it <= j + grid[i][j];
110+
it = bst1[i].erase(it)) {
111111
new_q.emplace_back(i, *it);
112-
sl2[*it].erase(i);
112+
bst2[*it].erase(i);
113113
}
114-
for (auto it = sl2[j].lower_bound(i + 1);
115-
it != end(sl2[j]) && *it <= i + grid[i][j];
116-
it = sl2[j].erase(it)) {
114+
for (auto it = bst2[j].lower_bound(i + 1);
115+
it != end(bst2[j]) && *it <= i + grid[i][j];
116+
it = bst2[j].erase(it)) {
117117
new_q.emplace_back(*it, j);
118-
sl1[*it].erase(j);
118+
bst1[*it].erase(j);
119119
}
120120
}
121121
q = move(new_q);

0 commit comments

Comments
 (0)