class TreeNode {
int val;
TreeNode left;
TreeNode right;
TreeNode(int x) { val = x; }
}
public class Solution6 {
public int maxDepth(TreeNode root) {
if(root == null)
return 0;
int ld = maxDepth(root.left);//左子树高度
int rd = maxDepth(root.right);//右子树高度
if(ld > rd)//比较左右子树高度、取较大的高度
return ld+1;
else
return rd+1;
}
}
}