public class Solution { public boolean IsBalanced_Solution(TreeNode root) { if (root == null) { return true; } int left = TreeDepth(root.left); int right = TreeDepth(root.right); return Math.abs(left - right) <= 1; } public int TreeDepth(TreeNode root) { if (root == null) { return 0; } int left = TreeDepth(root.left); int right = TreeDepth(root.right); return Math.max(right, left) + 1; } }