剑指 Offer 55 - II. 平衡二叉树
作者:互联网
package leetcode; public class offer_55_2 { public boolean isBalanced(TreeNode root) { if(root==null) { return true; } return isBalanced(root.left)&&isBalanced(root.right)&&Math.abs(treeHeight(root.left)-treeHeight(root.right))<=1; } public int treeHeight(TreeNode root) { return root==null?0:Math.max(treeHeight(root.left),treeHeight(root.right))+1; } }
标签:right,return,55,treeHeight,II,isBalanced,二叉树,root,public 来源: https://www.cnblogs.com/Yshun/p/16025795.html