JavaScript Solution Here


  • 0
    F
    var mergeTrees = function(t1, t2) {
        var root = null
        if (t1 && t2) {
            root =  new TreeNode(null);
            root.val = (t1.val) + (t2.val);
            root.left = mergeTrees(t1.left, t2.left);
            root.right = mergeTrees(t1.right, t2.right);
        } else if (t1) {
            root = t1
        } else if (t2){
            root = t2
        } 
        return root;
    };
    

Log in to reply
 

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