#110.Balanced Binary Tree [LeetCode Grind 75 in Java]

[Problem Link] https://leetcode.com/problems/balanced-binary-tree/

class Solution {
    public boolean ans = true;

    public int checkHeightDiff(TreeNode node){
        if(node == null) return 0;

        int leftht = checkHeightDiff(node.left);
        int rightht = checkHeightDiff(node.right);

        if(Math.abs(leftht - rightht) > 1) ans = false;
        return Math.max(leftht , rightht) + 1;
    }
    public boolean isBalanced(TreeNode root) {
        checkHeightDiff(root);
        return ans;
    }
}