title: What is the wrong in my code(all paths from source to target)?
body: <p>Problem statement:
  <a href="https://leetcode.com/problems/all-paths-from-source-to-target/" rel="nofollow noreferrer">Question link</a></p>
  <blockquote>
  <p>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.</p>
  <p>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]).</p>
  </blockquote>
  <p>Input:</p>
  <pre><code>[[1,2],[3],[3],[]]
  </code></pre>
  <p>Output:</p>
  <pre><code>[[0,1,3],[0,2,3]]
  </code></pre>
  <p>This is my code :</p>
  <pre><code>class Solution:
  def allPathsSourceTargetUtil(self, n, graph, visited, ans):
      visited.append(n)
      
      if n == len(graph)-1:
          ans.append(visited)
          print(ans)
      else:
          for i in graph[n]:
              self.allPathsSourceTargetUtil(i, graph, visited, ans)
          
              visited.pop()
      
      
  def allPathsSourceTarget(self, graph: List[List[int]]) -&gt; List[List[int]]:
      ans  = []
      visited = []
      n = 0
      
      self.allPathsSourceTargetUtil(n, graph, visited, ans)
      
      return ans
  </code></pre>
  <p>And this is input:</p>
  <pre><code>[[1,2],[3],[3],[]]
  </code></pre>
  <p>And real Output:</p>
  <pre><code>[[0,1,3],[0,2,3]]
  </code></pre>
  <p>But I get this output from my code:</p>
  <pre><code>[[0, 1, 3]]
  [[0, 2, 3], [0, 2, 3]]
  
  [[0],[0]]
  </code></pre>
  <p>Please help me for find out problem in this code.</p>