平衡二叉树:也叫AVL树,它有如下性质,是空树或者是它的左右子树高度差的绝对值不超过1,且左右子树为平衡二叉树。公共类解决方案{publicbooleanisBalanced(TreeNoderoot){if(root==null){returntrue;}返回Math.abs(getDepth(root.left)-getDepth(root.right))<=1&&isBalanced(root.left)&&isBalanced(root.right));}publicintgetDepth(TreeNoderoot){if(root==null)返回0;intleft=getDepth(root.left);intright=getDepth(root.right);返回Math.max(左,右)+1;}}
