While answers are right as per the definition of the max depth as per this question, it isn't a universal definition of the depth of the binary tree. As far as I know, the depth is number of edges, not the nodes themselves. It means that a binary tree constructed out of [1,2,3,4] would have max depth of 2 , not 3. Hope that administrator will take a note of it. Here is the definition I found elsewhere:

"The depth of a node is the number of edges from the node to the tree's root node. A root node will have a depth of 0. The height of a node is the number of edges on the longest path from the node to a leaf. A leaf node will have a height of 0."

So going by that definition, we should have ideally done this:

```
if(root.left==null && root.right==null) {
return 0;
}
```