public class Solution {

public int maxDepth(TreeNode root) {

```
LinkedList<TreeNode> queue=new LinkedList<TreeNode>();
TreeNode p;
if(root==null) return 0;
root.val=1;
queue.add(root);
int height=0;
while(!queue.isEmpty())
{
p=queue.getFirst();
if(p.left!=null)
{
p.left.val=p.val+1;
queue.add(p.left);
}
else if(p.right!=null)
{
p.right.val=p.val+1;
queue.add(p.right);
}
height=p.val;
queue.removeFirst();
}
return (height);
```

}

}