Skip to content

Commit ca78f6a

Browse files
authored
Update minimum-moves-to-move-a-box-to-their-target-location.cpp
1 parent 0423211 commit ca78f6a

File tree

1 file changed

+6
-6
lines changed

1 file changed

+6
-6
lines changed

C++/minimum-moves-to-move-a-box-to-their-target-location.cpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -45,15 +45,15 @@ class Solution {
4545
swap(closer, detour);
4646
}
4747
const auto [b, p] = closer.back(); closer.pop_back();
48+
if (b == t) {
49+
return f;
50+
}
4851
if (lookup.count({b.first * grid[0].size() + b.second,
4952
p.first * grid[0].size() + p.second})) {
5053
continue;
5154
}
5255
lookup.emplace(b.first * grid[0].size() + b.second,
5356
p.first * grid[0].size() + p.second);
54-
if (b == t) {
55-
return f;
56-
}
5757
for (const auto& [dx, dy] : directions) {
5858
pair<int, int> nb = {b.first + dx, b.second + dy}, np = {b.first - dx, b.second - dy};
5959
if (!(0 <= nb.first && nb.first < grid.size() &&
@@ -93,13 +93,13 @@ class Solution {
9393
swap(closer, detour);
9494
}
9595
auto p = closer.back(); closer.pop_back();
96+
if (p == t) {
97+
return true;
98+
}
9699
if (lookup.count(p.first * grid[0].size() + p.second)) {
97100
continue;
98101
}
99102
lookup.emplace(p.first * grid[0].size() + p.second);
100-
if (p == t) {
101-
return true;
102-
}
103103
for (const auto& [dx, dy] : directions) {
104104
pair<int, int> np = {p.first + dx, p.second + dy};
105105
if (!(0 <= np.first && np.first < grid.size() &&

0 commit comments

Comments
 (0)