```
class Solution {
public int maxDepth(TreeNode root) {
int leftDepth = 0 ;
int rightDepth = 0;
int maxDepth = 0;
if (root == null) return 0;
else {
leftDepth += 1 + maxDepth(root.left);
rightDepth += 1 + maxDepth(root.right);
maxDepth = Math.max(leftDepth,rightDepth);
return maxDepth;
}
}
}
```