title: Get the distance from a root to a node with given value in a binary tree: Algorithm correctness
body: <p>Here's my code</p>
  
  <pre><code> public int getDist(Node root, int value)
    {
      if (root == null &amp;&amp; value !=0)
        return -1;//
      if(root.value == value)// we have a match
        return 0;
      if(root.getLeft()!=null)
      int left =1+ getDist(root.getLeft(),value);
      int right = 1+getDist(root.getRight(),value);
      if(left ==-1 &amp;&amp;  right== -1)
        return -1;//not found
      return Math.max(left,right);
    }
  </code></pre>
  
  <p>I would appreciate any feedback on the correctness of the above approach or any optimizations. </p>