题解 | #牛群的最大高度#

牛群的最大高度

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

所用语言

Java

所用知识

二叉树遍历

解题思路

可以采用不同的方式遍历二叉树,找出最大值即可

完整代码

public int findMaxHeight (TreeNode root) {
    // write code here
    if(root==null){
        return 0;
    }else{
        int maxValue=root.val;
        int leftValue=findMaxHeight(root.left);
        if(leftValue>maxValue){
            maxValue=leftValue;
        }
        int rightValue=findMaxHeight(root.right);
        if(rightValue>maxValue){
            maxValue=rightValue;
        }
       return maxValue;
    }
}
#牛群的最大高度#
全部评论

相关推荐

迷茫的大四🐶:你这个拿去投央国企吧,投私企包过不了的
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

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