如何求一棵二叉树的深度

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

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;
                  }
              }
    }

版权声明:本文为wengsy_5041原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接和本声明。