public class Solution { public int TreeDepth(TreeNode root) { //空节点没有深度 if(root == null) return 0; //返回子树深度+1 return Math.max(TreeDepth(root.left), TreeDepth(root.right)) + 1; } }
好简单啊