![](https://img-blog.csdnimg.cn/20201014180756928.png?x-oss-process=image/resize,m_fixed,h_64,w_64)
DFS
一杯小熊
这个作者很懒,什么都没留下…
展开
-
LeetCode 200 岛屿数量
class Solution: def numIslands(self, grid: [[str]]) -> int: def dfs(grid, i, j): if not 0 <= i < len(grid) or not 0 <= j < len(grid[0]) or grid[i][j] == '0': return grid[i][j] = '0' dfs(gr...原创 2021-04-12 11:04:33 · 49 阅读 · 0 评论 -
剑指Offer 12 矩阵中的路径
将矩阵看作无向图,因此用深度优先或者广度优先class Solution: def exist(self, board: List[List[str]], word: str) -> bool: m, n = len(board), len(board[0]) def dfs(i, j , k): if not 0 <= i < m or not 0 <= j < n or board[i][j] !=...原创 2021-02-25 10:48:32 · 54 阅读 · 0 评论