mirror of
https://github.com/youngyangyang04/leetcode-master.git
synced 2025-07-09 02:53:31 +08:00
修改: 0617 合并二叉树
修改代码细节,优化性能. 用原有的Root1 代替 创建的NewRoot.
This commit is contained in:
@ -262,10 +262,10 @@ class Solution {
|
||||
if (root1 == null) return root2;
|
||||
if (root2 == null) return root1;
|
||||
|
||||
TreeNode newRoot = new TreeNode(root1.val + root2.val);
|
||||
newRoot.left = mergeTrees(root1.left,root2.left);
|
||||
newRoot.right = mergeTrees(root1.right,root2.right);
|
||||
return newRoot;
|
||||
root1.val += root2.val;
|
||||
root1.left = mergeTrees(root1.left,root2.left);
|
||||
root1.right = mergeTrees(root1.right,root2.right);
|
||||
return root1;
|
||||
}
|
||||
}
|
||||
```
|
||||
|
Reference in New Issue
Block a user