输入一棵二叉树判断二叉树是不是平衡二叉树

public boolean IsBalanced_Solution(TreeNode root) {
        if(root == null) return true;
        int left = getDepth(root.left);
        int right = getDepth(root.right);
        if(Math.abs(left-right)>1) return false;
        return IsBalanced_Solution(root.left)&&IsBalanced_Solution(root.right);
    }
    public int getDepth(TreeNode root){
        if(root == null) return 0;
        return Math.max(getDepth(root.left),getDepth(root.right))+1;
    }
原文地址:https://www.cnblogs.com/yingpu/p/5828774.html