图片说明

/* function TreeNode(x) {
    this.val = x;
    this.left = null;
    this.right = null;
} */
function IsBalanced_Solution(pRoot)
{
    // write code here
    if(!pRoot) return true
    function dfs(root){
        if(!root) return 0
        return Math.max(dfs(root.left),dfs(root.right))+1
    }
    let left = dfs(pRoot.left)
    let right = dfs(pRoot.right)
    if(left-right>1 || right-left >1) return false
    return true
}
module.exports = {
    IsBalanced_Solution : IsBalanced_Solution
};