(int[][] graph)
| 1 | class Solution { |
| 2 | public List<Integer> eventualSafeNodes(int[][] graph) { |
| 3 | // V+E |
| 4 | // V |
| 5 | HashMap<Integer,Boolean> map = new HashMap<>(); |
| 6 | int n = graph.length; |
| 7 | List<Integer> res = new ArrayList<>(); |
| 8 | for(int i=0;i<n;i++){ |
| 9 | if(dfs(i,graph,map)){ |
| 10 | res.add(i); |
| 11 | } |
| 12 | } |
| 13 | return res; |
| 14 | } |
| 15 | public boolean dfs(int node, int[][] graph, HashMap<Integer,Boolean> map){ |
| 16 | if(map.containsKey(node)){ |
| 17 | return map.get(node); |