public class TreeNode {
       int val = 0;
       TreeNode left = null;
       TreeNode right = null;
   
       public TreeNode(int val) {
           this.val = val;
   
       }
   
   }
public static int TreeDepth(TreeNode root) {
    if(root==null){
        return 0;
    }
    int right = TreeDepth(root.right);
    int left= TreeDepth(root.left);
    return Math.max(right,left)+1;
    
}

二叉树递归 详解

 

相关文章:

  • 2021-06-22
  • 2022-12-23
  • 2021-11-21
  • 2021-08-23
  • 2021-09-07
  • 2021-05-27
猜你喜欢
  • 2021-12-12
  • 2022-12-23
  • 2021-06-27
  • 2022-12-23
  • 2021-12-27
  • 2022-12-23
  • 2021-07-31
相关资源
相似解决方案