1. class Solution {
    2. public int maxDepth(TreeNode root) {
    3. if (root == null) {
    4. return 0;
    5. }
    6. int leftDepth = maxDepth(root.left);
    7. int rightDepth = maxDepth(root.right);
    8. return Math.max(leftDepth, rightDepth) + 1;
    9. }
    10. }