> For the complete documentation index, see [llms.txt](https://lfool.gitbook.io/data-structure/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://lfool.gitbook.io/data-structure/chang-yong-suan-fa/er-cha-shu-shen-du.md).

# 二叉树深度

```java
public int treeDepth(TreeNode root) {
    if (root == null) return 0;
    
    return Math.max(treeDepth(root.left), treeDepth(root.right)) + 1;
}
```
