title: Given a binary tree and a sum, find all root-to-leaf paths where each path's sum equals the given sum
body: <p><strong>Why is "path.remove(path.size()-1)" used in the end?</strong></p>
  
  <p>This code is for finding all root to leaf paths whose sum is equal to given sum.  </p>
  
  <pre><code>public List&lt;List&lt;Integer&gt;&gt; pathSum(TreeNode root, int sum) {
      List&lt;List&lt;Integer&gt;&gt; res = new ArrayList&lt;List&lt;Integer&gt;&gt;();
      ArrayList&lt;Integer&gt; path = new ArrayList&lt;Integer&gt;();
      pathSumRe(root, sum, res, path);
      return res;
  }
  public void pathSumRe(TreeNode root, int sum, List&lt;List&lt;Integer&gt;&gt; res,
          ArrayList&lt;Integer&gt; path) {
  
      if (root == null)
          return;
  
      path.add(root.val);
  
      if (root.left == null &amp;&amp; root.right == null &amp;&amp; root.val == sum) {
  
          ArrayList&lt;Integer&gt; tmp = new ArrayList&lt;Integer&gt;(path);
          res.add(tmp);
      }
  
      pathSumRe(root.left, sum - root.val, res, path);
      pathSumRe(root.right, sum - root.val, res, path);
      path.remove(path.size() - 1);
  }
  </code></pre>
  
  <p>Removing "path.remove(path.size() - 1);" from the code will give the following output.</p>
  
  <p>Input: [0,1,1], 1</p>
  
  <p>Output: [[0,1],[0,1,1]]  ==> This is the wrong output</p>
  
  <p>Expected Output: [[0,1],[0,1]]</p>