题解 | #字符串的排列#
平衡二叉树
http://www.nowcoder.com/practice/8b3b95850edb4115918ecebdf1b4d222
public boolean IsBalanced_Solution(NC14.TreeNode root) { if (root == null){ return true; } if (Math.abs(depth(root.left) - depth(root.right)) > 1){ return false; } return IsBalanced_Solution(root.left) && IsBalanced_Solution(root.right); } public int depth(NC14.TreeNode root){ if (root == null){ return 0; }else { return 1 + Math.max(depth(root.left), depth(root.right)); } }若一棵树为平衡二叉树,则其左子树和右子树也比为平衡二叉树。根据树的左右子树的高度差判断这棵树到底是不是平衡二叉树。