树的深度
有关深度的题: 104. 二叉树的最大深度 DFS递归: 时间复杂度:O(N) 空间复杂度:最坏O(N)(斜二叉树),最好O(logN)(完全二叉树) class Solution { public int maxDepth ( TreeNode root ) { return root == null ? 0 : Math . max ( maxDepth ( root . left ) , maxDepth ( root . right ) ) + 1 ; } } 111. 二叉树的最小深度 DFS递归 class Solution { public int minDepth ( TreeNode root ) { if ( root == null ) return 0 ; if ( ( root . left == null ) && ( root . right == null ) ) return 1 ; int min_depth = Integer . MAX_VALUE ; if ( root . left != null ) min_depth = Math . min ( minDepth ( root . left ) , min_depth ) ; if ( root . right != null ) min_depth = Math . min (