mirror of
https://github.com/youngyangyang04/leetcode-master.git
synced 2025-07-08 00:43:04 +08:00
Update 0617.合并最大二叉树,添加C#版
This commit is contained in:
@ -788,6 +788,20 @@ impl Solution {
|
||||
}
|
||||
}
|
||||
```
|
||||
### C#
|
||||
```C#
|
||||
public TreeNode MergeTrees(TreeNode root1, TreeNode root2)
|
||||
{
|
||||
if (root1 == null) return root2;
|
||||
if (root2 == null) return root1;
|
||||
|
||||
root1.val += root2.val;
|
||||
root1.left = MergeTrees(root1.left, root2.left);
|
||||
root1.right = MergeTrees(root1.right, root2.right);
|
||||
|
||||
return root1;
|
||||
}
|
||||
```
|
||||
|
||||
<p align="center">
|
||||
<a href="https://programmercarl.com/other/kstar.html" target="_blank">
|
||||
|
Reference in New Issue
Block a user