*简单总结一下几种树:1.平衡二叉树,2.二叉搜索树,3.镜像树,4.哈夫曼树

  • 1.平衡二叉树,左右子树高度差小于等于1
  • 2.二叉搜索树,左子树全小于根节点,右子树全大于根节点,中序遍历是单调递增序列
  • 3.镜像树,反转原树
  • 4.哈夫曼树,集合中选两个值最小的求和,构建小树,然后继续添加最小节点与当前树上节点或者集合中节点构建次小的值构建小树,后续将其全部链接起来。
public class Solution {
    public boolean IsBalanced_Solution(TreeNode root) {
        if(root==null) {
            return true;
        }
        return Math.abs(TreeDepth(root.left)-TreeDepth(root.right))<=1;

    }
    public int TreeDepth(TreeNode root) {
        if(root==null) {
            return 0;
        }
        return Math.max(1+TreeDepth(root.left), 1+TreeDepth(root.right));
    }
}