There is a directed graph of n nodes labeled from n graph, where graph[i] is an integer array of nodes adjacent to node i, meaning there is a directed edge from node i to each node in graph[i].
A node is considered a terminal node if it has no outgoing edges. A node is a safe node if every possible path starting from that node leads to a terminal node.
Return an array containing all the safe nodes of the graph, sorted in ascending order.
Constraints:
n graph.length
n
graph[i].length n
graph[i][j] n
graph[i] is sorted in strictly increasing order.
The graph may contain self loops.
The total number of edges in the graph is in the range
There is a directed graph of n nodes labeled from n graph, where graph[i] is an integer array of nodes adjacent to node i, meaning there is a directed edge from node i to each node in graph[i].
A node is considered a terminal node if it has no outgoing edges. A node is a safe node if every possible path starting from that node leads to a terminal node.
Return an array containing all the safe nodes of the graph, sorted in ascending order.
Constraints:
n graph.length
n
graph[i].length n
graph[i][j] n
graph[i] is sorted in strictly increasing order.
The graph may contain self loops.
The total number of edges in the graph is in the range