I don't even know where to start


  • 0
    N

    I can make a function that solves the problem, like this:

    var mergeTrees = function(t1, t2) {
        var result = [];
        for(var i = 0; i < t1.length; i++){
           if(!t2[i]){
           result.push(t1[i]);
           }else{
           result.push(t1[i] + t2[i]);
           }
        }
        if (t2.length > t1.length){
            for(var i = t1.length; i < t2.length; i++)
                result.push(t2[i]);
        }
        return result;
    }
    

    But is doesn't work on here, it works fine on js fiddle. Can someone link a resource to explain this portion of the code:

    /**
     * Definition for a binary tree node.
     * function TreeNode(val) {
     *     this.val = val;
     *     this.left = this.right = null;
     * }
     */
    /**
     * @param {TreeNode} t1
     * @param {TreeNode} t2
     * @return {TreeNode}
     */
    

    I know it is a comment explaining a function to me but I don't understand what it does or how to use it. I also know it isn't unique to this problem, many of the leetcode problems use something like it. Thanks for the help.


Log in to reply
 

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