JavaScript BFS 9-Line Solution


  • 0
    var isBalanced = function(root) {
        if(!root) return true;
        function getHeight(root){
            if(!root) return 0;
            return 1 + Math.max(getHeight(root.left), getHeight(root.right));
        }
        if(Math.abs(getHeight(root.left) - getHeight(root.right)) > 1) return false;    
        return isBalanced(root.left) && isBalanced(root.right);        
    };

Log in to reply
 

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.