Concise JavaScript solution


  • 0
    var tree2str = function(t) {
        if (!t) return '';
        const left = tree2str(t.left);
        const right = tree2str(t.right);
        return t.val + (left || right ? `(${left})` : '') + (right ? `(${right})` : '');
    };
    

Log in to reply
 

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