【发布时间】:2021-09-08 10:29:00
【问题描述】:
我想知道为什么这个解决方案适用于 LeetCode,因为当我在控制台中记录函数的输出时,它对我来说似乎是一堆废话:[ 1, 3, 2, 5, val: NaN, left: undefined, right: undefined ] 这与 LeetCode 上显示的输出不同。
我是编程新手,非常感谢您的帮助!
问题: LeetCode
我不明白的代码:
const mergeTrees = (t1, t2) => {
if (!t1) {
return t2;
}
if (!t2) {
return t1;
}
t1.val += t2.val;
t1.left = mergeTrees(t1.left, t2.left);
t1.right = mergeTrees(t1.right, t2.right);
return t1;
};
console.log(mergeTrees([1,3,2,5],
[2,1,3,null,4,null,7]))
leetcode 输出:[3,4,5,5,4,null,7]
我的 console.log 输出:[ 1, 3, 2, 5, val: NaN, left: undefined, right: undefined ]
【问题讨论】:
-
你能把代码贴在这里吗?
-
你是对的。没有意义
-
你在哪里找到这个解决方案?