LeetCode题库–二叉树的深度 使用递归,结束条件:f(null)= 0; f(n)= Max(left,right)+ 1 // treeNode代表树的深度 public int treedepth(TreeNode root) { //结束条件 if (root == null) return 0; //左子树深度 int left = treedepth(root.left); //右子树深度 int right = treedepth(root.right); //最大深度 + root(1) return Math.max(left, right) + 1; }