几天没写代码,写个递归在这想了半个小时。
就递归地判断两个子树是否是平衡二叉树就玩了,递归出口条件死活想不出来。
打小就看准了我以后成不了气候

public class Solution {
    public boolean IsBalanced_Solution(TreeNode root) {
        if(root==null){
            return true;
        }
        if(Math.abs(getDepth(root.left,0)-getDepth(root.right,0))<=1){
            return IsBalanced_Solution(root.left)&&IsBalanced_Solution(root.right);
        }
        return false;
    }
    public int getDepth(TreeNode root,int currentLength){
        if(root!=null){
            currentLength++;
            return Math.max(getDepth(root.left,currentLength),getDepth(root.right,currentLength));
        }
        return currentLength;
    }
}