如何求一棵二叉树的深度

来源:互联网 发布:通话录音软件 免费 编辑:程序博客网 时间:2024/06/05 09:43

如何求一棵二叉树的深度,递归实现:

public static int getLength(Node root){               if(root==null)                return 0;               int depth1;               int depth2;               else{                   depth1 = getLength(root.left);                   depth2 = getLength(root.right);                   if(depth1>depth2){                   return depth1+1;                   }else{                   return depth2+1;                  }              }    }