对于自己掌握的不是很熟练的算法,完成题目之后,总结是十分必要的,以后复习起来很方便。
1. 深度优先搜索算法
(1)深度优先搜索算法是用来遍历图中的节点的;
(2)一般从初始节点开始,逐步深入遍历各个节点,直到找到目标节点或者没有子节点的节点;
(3)算法常用的数据结构是堆栈。
简单地说,
(1)一直走到底
(2)栈,入栈,出栈
2. 题目算法描述
Given a directed acyclic graph (DAG) of n nodes labeled from 0 to n - 1, find all possible paths from node 0 to node n - 1, and return them in any order.
The graph is given as follows: graph[i] is a list of all nodes you can visit from node i (i.e., there is a directed edge from node i to node graph[i][j]).
Example: