标签:
/*
* Given a binary tree, determine if it is height-balanced.
For this problem, a height-balanced binary tree is defined as a binary tree in which the depth of the two subtrees of every node never differ by more than 1.
* */
//判断二叉平衡树:
//
public boolean isBalanced(TreeNode root) { if(root==null) { return false; } if (root.right==null&&root.left==null) { return true; } int a = maxDepth(root.left); int b = maxDepth(root.right); boolean suba = isBalanced(root.left); boolean subb = isBalanced(root.right); if(Math.abs(a-b)>1) { return false; } if (suba && subb) { return true; } return false; }
标签:
原文地址:http://www.cnblogs.com/theonemars/p/4254091.html