Find Eventual Safe States

Given a directed graph as an adjacency list graph with n nodes numbered 0 to n - 1, implement solve(graph). A node is eventually safe if every path starting from it ends at a terminal node with no outgoing edges. Equivalently, no path from the node enters a cycle. Return all eventually safe node labels in ascending order.

Examples
Input: [[1,2],[2,3],[5],[0],[5],[],[]]
Output: [2,4,5,6]
Hints

Find Eventual Safe States

Given a directed graph as an adjacency list `graph` with `n` nodes numbered `0` to `n - 1`, implement `solve(graph)`. A node is eventually safe if every path starting from it ends at a terminal node with no outgoing edges. Equivalently, no path from the node enters a cycle. Return all eventually safe node labels in ascending order.