title: Python - append list to other list?
body: <p>Leetcode 113 - Path Sum II</p>
  <p>Given the root of a binary tree and an integer targetSum, return all root-to-leaf paths where each path's sum equals targetSum.</p>
  <pre><code># Definition for a binary tree node.
  # class TreeNode:
  #     def __init__(self, val=0, left=None, right=None):
  #         self.val = val
  #         self.left = left
  #         self.right = right
  
  class Solution:
      def pathSum(self, root: TreeNode, targetSum: int) -&gt; List[List[int]]:
          if not root: return []
          
          res = []
          
          def dfs(node, total = 0, path = []):
              if not node: return 
              
              path.append(node.val)
              total += node.val
              if not node.left and not node.right and total == targetSum:
                  res.append(list(path))
              else:
                  dfs(node.left, total, path)
                  dfs(node.right, total, path)
              total -= path.pop()
          
          dfs(root)
          return res
  </code></pre>
  <p>Why we have to use <code>res.append(list(path))</code> rather than use <code>res.append(path)</code>?</p>
  <p>If we only append <code>path</code> into res, it would only append empty list into <code>res</code>.</p>