解题思路:二叉树的高度(深度)可以认为是左右子树的最大高度 + 1;
public int maxDepth(TreeNode root) {
int leftHeight = 0, rightHeight = 0;
if (root == null) {
return 0;
}
if (root.lefNode != null)
leftHeight = maxDepth(root.lefNode);
if (root.rightNode != null)
rightHeight = maxDepth(root.rightNode);
return Math.max(leftHeight, rightHeight) + 1;
}