知识点/数据结构:二叉树
题目描述
输入一棵二叉树,判断该二叉树是否是平衡二叉树。
//一次编译通过!!!!!!!加油这是个信号。头条,等我!!!!!1
public class Solution {
public boolean IsBalanced_Solution(TreeNode root) {
if (root==null) return true;
if(Math.abs(TreeDepth(root.left)-TreeDepth(root.right))>1)
{
return false;
}
return IsBalanced_Solution(root.left)&&IsBalanced_Solution(root.right);
}
public int TreeDepth(TreeNode root) {
//2018.10.07找了大王八取经,梦想还是要有的。
//2018.11.19最后一次的机会
if(root==null){
return 0;
}
int nLelt=TreeDepth(root.left);
int nRight=TreeDepth(root.right);
return nLelt>nRight?(nLelt+1):(nRight+1);
}
}
2018.12.12双十二来了哦 ,一年又过去了,一个月又过去了,走走停停,有过迷茫,有过’大彻大悟‘,做自己喜欢左的事情,对自己好点,对对自己好的人好点。更爱你的家人。往事不回头,以后不将就。