1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
|
public class { public boolean IsBalanced_Solution(TreeNode root) { if(root==null){ return true; } if(Math.abs(TreeHeight(root.left) - TreeHeight(root.right)) <= 1) { return IsBalanced_Solution(root.left)&&IsBalanced_Solutio(root.right); }else{ return false; } } public int TreeHeight(TreeNode root){ if(root == null) { return 0; } return Math.max(TreeHeight(root.left), TreeHeight(root.right)) + 1; } }
|
近期评论