110.平衡二叉树
/**
* Definition for a binary tree node.
* public class TreeNode {
* int val;
* TreeNode left;
* TreeNode right;
* TreeNode(int x) { val = x; }
* }
*/
class Solution {
public boolean isBalanced(TreeNode root) {
if (root == null) return true;
Height(root);
return isBal;
}
boolean isBal = true;
private int Height(TreeNode node){
if(node == null) return 0;
int left = 0,right = 0;
left = Height(node.left);
right = Height(node.right);
if(Math.abs(left-right) > 1) isBal = false;
return Math.max(left,right)+1;
}
}