Java Solution using post order traversal


#1

Comment body goes here.

public class Solution {
int isBalancedBT = 1;
public int isBalanced(TreeNode A) {
getHeight(A);
return isBalancedBT;
}
public int getHeight(TreeNode curr) {
if(curr == null)
return 0;
int lHt = getHeight(curr.left);
int rHt = getHeight(curr.right);
if(Math.abs(lHt-rHt) > 1) {
isBalancedBT = 0;
}
return 1 + Math.max(lHt, rHt);
}
}