We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
这是一题类岛屿问题,分析情况:
这题可以去重,可以避免走重复的路径
function updateBoard(board: string[][], click: number[]): string[][] { const x = click[0] const y = click[1] if (board[x][y] === 'M') { board[x][y] = 'X' return board } const rowLimit = board.length const colLimit = board[0].length const visited = new Set() const ways = [ [-1, -1], [-1, 0], [-1, 1], [0, -1], [0, 1], [1, -1], [1, 0], [1, 1] ] const dfs = function (x: number, y: number): number { if (board[x][y] === 'M' || board[x][y] === 'X') return 1 const str = `${x},${y}` if (board[x][y] !== 'E' || visited.has(str)) return 0 visited.add(str) let count = 0 for (const way of ways) { const r = way[0] + x const c = way[1] + y if (r < 0 || r >= rowLimit || c < 0 || c >= colLimit) continue if (board[r][c] === 'M' || board[r][c] === 'X') count++ } if (count === 0) { for (const way of ways) { const r = way[0] + x const c = way[1] + y if ( r < 0 || r >= rowLimit || c < 0 || c >= colLimit || visited.has(`${r},${c}`) ) continue dfs(r, c) } board[x][y] = 'B' } else { board[x][y] = count + '' } return 0 } dfs(x, y) return board }
The text was updated successfully, but these errors were encountered:
No branches or pull requests
529-扫雷游戏
这是一题类岛屿问题,分析情况:
这题可以去重,可以避免走重复的路径
The text was updated successfully, but these errors were encountered: