Js Simple Recursion


  • 0
    C
    var tree2str = function(t) {
        if (!t) return '';
        var leftR = tree2str(t.left);
        var rightR = tree2str(t.right);
        if (rightR) return t.val + '(' + leftR + ')(' + rightR + ')';
        if (leftR) return t.val + '(' + leftR + ')';
        return t.val + '';
    };
    

Log in to reply
 

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