class Solution {
bool flag;
public:
bool isBalanced(TreeNode *root) {
flag=true;
if(checkbal(root)){
return flag;
}
}
int checkbal(TreeNode *root){
int x,y;
if(root==NULL) return 1;
x=checkbal(root>left);
y=checkbal(root>right);
if(xy<=1 && xy>=1) {
if(x>y) return x+1;
else return y+1;
}
else{
flag=false;
return 0;
}
}
};
Balanced Binary tree


public class Solution { public boolean isBalanced(TreeNode root) { if(root==null) return true; if(height(root)==1) return false; return true; } public int height(TreeNode root){ if(root==null) return 0; int left=height(root.left); int right=height(root.right); if(left==1 right==1) return 1; if(Math.abs(leftright)>1) return 1; return Math.max(left,right)+1; } }

Thanks for your post. However it would be better to elaborate thoughts first, then ask for better solution. Please read the FAQ (http://oj.leetcode.com/discuss/faq) for more info.

Thanks for your post. However it would be better to share solution with elaborating thoughts. Please read the FAQ (http://oj.leetcode.com/discuss/faq) for more info.