import java.util.*;
public class Solution {
boolean ans = true;
public boolean IsBalanced_Solution(TreeNode root) {
dfs(root);
return ans;
}
public int dfs(TreeNode root) {
if(root == null) {
return 0;
}
int left, right;
//左边的高度
left = dfs(root.left);
//右边的高度
right = dfs(root.right);
if (Math.abs(left - right) > 1) {
ans = false;
}
return Math.max(left, right) + 1;
}
}