class Solution { public int maxDepth(TreeNode root) { //1:递归条件 if(root == null){ return 0; } //2: 递归方法 //这个写法非常精妙 递归的含义是:取左子树和右子树中,最深的一层,在加上本层自己的深度(+1) return Math.max(maxDepth(root.left),maxDepth(root.right)) + 1; }}