title: Sum of depth of all nodes in binary tree (Path length)
body: <p>I am trying to implement a function to calculate path length of a binary tree and i am not able to get the correct answer. Can you check what i am doing wrong? Here is my code below:</p>
  
  <pre><code>public int pathLength() {
      int sum = 0;
      int c = 1;
      pathLength(root, sum);
      return sum;
  }
  
  public int pathLength(Node n, int sum) {
      if(n.isRoot())
          sum+= 0;
      if(n.left == null &amp;&amp; n.right == null)
          return;
      c++;
      if(n.left != null)
          sum += c;
      if (n.right != null)
          sum+=c;
      pathLength(n.left, sum);
      pathLength(n.right, sum); 
  
  }
  </code></pre>