题解 | #牛群的最大高度#
牛群的最大高度
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;
}
}
#牛群的最大高度#