题解 | #二叉树的最大深度#
二叉树的最大深度
https://www.nowcoder.com/practice/8a2b2bf6c19b4f23a9bdb9b233eefa73
import java.util.*; public class Solution { // 定义递归函数功能:求出当前结点的 public int maxDepth (TreeNode root) { // 递归终止 if(root == null) { return 0; } // dfs,先递归左子结点,再递归右子结点,最后求出每一子树的深度的最大值 return Math.max(maxDepth(root.left), maxDepth(root.right)) + 1; } }