题解 | 迷宫寻路
迷宫寻路
https://www.nowcoder.com/practice/0c8930e517444d04b426e9703d483ed4
const rl = require("readline").createInterface({ input: process.stdin });
var iter = rl[Symbol.asyncIterator]();
const readline = async () => (await iter.next()).value;
void async function () {
// Write your code here
const graph = [];
const read = await readline();
let ans = 'No'
const [n,m] =read.split(' ').map(Number);
while(line = await readline()){
let tokens = line.split('')
graph.push(tokens);
}
function dfs(graph){
if(!graph||graph.length === 0)return;
const visited = new Set();
const stack = [];
function helper(r,c){
if(r<0||c<0||r>n-1||c>m-1)return;
if(graph[r][c]!=='.'){
return ;
}
if(r===n-1&&c===m-1){
ans = 'Yes';
}
visited.add([r,c]);
graph[r][c] = '#';
//想四个方向搜索道路
helper(r-1,c);
helper(r+1,c);
helper(r,c-1);
helper(r,c+1);
}
helper(0,0)
console.log(ans)
}
dfs(graph);
}()

