Javascript solution


  • 0
    R
    var hasPathSum = function(root, sum) {
        var a = false,
            b = false;
    
        if(root === null)
            return false;
        
        sum -= root.val;
        
        if(sum === 0 && root.left === null && root.right === null)
            return true;
        
        if(root.left !== null)
            a = hasPathSum(root.left, sum);
        if(root.right !== null)
            b = hasPathSum(root.right, sum);
        
        return a || b;
        
    };
    

Log in to reply
 

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