Skip to content

Commit

Permalink
impl the maze, but test failed
Browse files Browse the repository at this point in the history
  • Loading branch information
SKTT1Ryze committed Apr 23, 2024
1 parent 831d5b0 commit 6a26549
Showing 1 changed file with 44 additions and 2 deletions.
46 changes: 44 additions & 2 deletions leetcode-cc/TheMaze.hpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
#include <queue>
#include <unordered_set>
#include <utility>

#include "PairHash.h"
#include "TestHelper.h"
#include "problem.h"
#include "solution.h"
Expand Down Expand Up @@ -29,14 +32,53 @@ class STheMaze : public ISolution {
},
{0, 4},
{4, 4}},
{{
{0, 0, 1, 0, 0},
{0, 0, 0, 0, 0},
{0, 0, 0, 1, 0},
{1, 1, 0, 1, 1},
{0, 0, 0, 0, 0},
},
{0, 4},
{3, 2}},
},
{true}, [this](auto input) {
{true, false}, [this](auto input) {
return this->hasPath(get<0>(input), get<1>(input), get<2>(input));
});
};
int benchmark() const override { return 0; }

private:
bool hasPath(const vector<vector<int>>& maze, pair<int, int> start,
pair<int, int> destination) const {}
pair<int, int> destination) const {
int m = maze.size();
int n = maze[0].size();
queue<pair<int, int>> q = {};
q.push(start);
unordered_set<pair<int, int>, pair_hash> memo = {};

while (!q.empty()) {
auto current = q.front();
q.pop();

if (current == destination) {
return true;
}

memo.insert(current);

for (const auto& [x, y] :
vector<pair<int, int>>({{current.first - 1, current.second},
{current.first + 1, current.second},
{current.first, current.second - 1},
{current.first, current.second + 1}})) {
if (x >= 0 && x < m && y >= 0 && y < n && maze[x][y] == 0 &&
!memo.contains({x, y})) {
q.push({x, y});
}
}
}

return false;
}
};

0 comments on commit 6a26549

Please sign in to comment.