JavaScript Solution


  • 0
    F
    var tree2str = function(t) {
        var ret = ''
        if (t) {
            var tleft = t.left?`(${tree2str(t.left)})`:(t.right?'()':'');
            var tright = t.right?`(${tree2str(t.right)})`:'';
            ret = `${t.val}${tleft}${tright}`
        }
        return ret
    };
    

Log in to reply
 

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