Balanced Binary Tree
超简洁的代码
本来考虑是不是真的要每个点求一个maxDepth,看来是的哟
public class Solution { public boolean isBalanced(TreeNode root) { if (root==null) return true; if(Math.abs(maxDepth(root.right)-maxDepth(root.left))>1) return false; return isBalanced(root.left)&& isBalanced(root.right); } public int maxDepth(TreeNode root) { if(root==null) return 0; return(1+ Math.max(maxDepth(root.left),maxDepth(root.right))); } }