题解 | #牛群排列的最大深度#

牛群排列的最大深度

https://www.nowcoder.com/practice/b3c6383859a142e9a10ab740d8baed88

所用知识

二叉树

所用语言

java

解题思路

使用递归进行深度遍历

完整代码

public int maxDepth (TreeNode root) {
    // write code here
    if (root == null) {
        return 0;
    } else {
        int leftHeight = maxDepth(root.left);
        int rightHeight = maxDepth(root.right);
        return Math.max(leftHeight, rightHeight) + 1;
    }
}
#牛群排列的最大深度#
全部评论

相关推荐

评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务