Merge pull request #1526 from AronJudge/main

修改: 0617 合并二叉树
This commit is contained in:
程序员Carl 2022-07-21 09:39:11 +08:00 committed by GitHub
commit 8f8c59aeed
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 4 additions and 4 deletions

View File

@ -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;
}
}
```