harrysimply / learn-algorithm

0 stars 0 forks source link

深度优先搜索 Depth-First-Search #2

Open harrysimply opened 2 years ago

harrysimply commented 2 years ago

DFS

  1. 什么时候使用DFS?
harrysimply commented 2 years ago

【简单】

733. Flood Fill

向题目给定点四个方向做深度搜索,执行涂色任务;设立两个终止条件,当dfs数组坐标越界搜索终止;当搜索坐标与涂色颜色相同终止;当搜索坐标与指定坐标颜色不同时终止。

【中等】

695. Max Area of Island

用0和1表示的岛屿,扫描每一个点,找到值为1的点然后使用dfs搜索找到周边的点,dfs返回这个点所在岛屿的面积。同时dfs也将便利过的1值归0.

116. Populating Next Right Pointers in Each Node

将左侧树节点链表指针指向右侧树节点。