Open lpatmo opened 5 years ago
var mergeTrees = function(t1, t2) {
//if both trees have no children, return sum of root nodes
if (t1 && !t2) { return t1; }
if (!t1 && t2) { return t2; }
if (!t1 && !t2) { return null; }
t1.val += t2.val;
t1.left = mergeTrees(t1.left, t2.left);
t1.right = mergeTrees(t1.right, t2.right);
return t1;
};
https://leetcode.com/problems/merge-two-binary-trees/submissions/