Javascript Solution


  • 0
    /**
     * @param {TreeNode} root
     * @return {string[]}
     */
    var binaryTreePaths = function(root) {
        var list = [];
    
        var tracer = function(root, trace) {
            if (!root) {
                return;
            }
    
            trace += root.val + "->";
    
            tracer(root.left, trace);
            tracer(root.right, trace);
    
            if (!root.left && !root.right) {
                list.push(trace.slice(0, trace.length - 2));
            }
    
        };
    
        tracer(root, "");
        return list;    
    };
    

Log in to reply
 

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