leetcode-104。バイナリツリーの最大深度

件名:https : //leetcode-cn.com/problems/maximum-depth-of-binary-tree/submissions/

回答:

二分木探索再帰

  public int maxDepth(TreeNode root){

  if(root == null){

            0を返します。

        }そうしないと {

            int heightLeft = 1 + maxDepth(root.left);

            int heightRight = 1 + maxDepth(root.right);

            Math.max(heightLeft、heightRight);を返します。

        }

    }

おすすめ

転載: blog.csdn.net/wuqiqi1992/article/details/108326672