title: Diameter of Binary Tree - Better Design
body: <p>I have written a code for finding diameter of Binary Tree.
  Need suggestions for the following:</p>
  
  <ol>
  <li>Can I do this without using static variable at class level?</li>
  <li><p>Is the algorithm fine/any suggestions? </p>
  
  <pre><code>public class DiameterOfTree {   
  public static int diameter = 0; 
  public static int getDiameter(BinaryTreeNode root) {        
      if (root != null) {                     
          int leftCount = getDiameter(root.getLeft());
          int rightCount = getDiameter(root.getRight());
          if (leftCount + rightCount &gt; diameter) {
              diameter = leftCount + rightCount;
              System.out.println("---diameter-------------&gt;" + diameter);
          }           
          if ( leftCount &gt; rightCount) {
              return leftCount + 1;
          }
          return rightCount + 1;
      }
      return 0;
    }
  }
  </code></pre></li>
  </ol>