Skip to content

Commit 21c05df

Browse files
committed
Added solution 617
1 parent 578c85e commit 21c05df

File tree

1 file changed

+33
-0
lines changed

1 file changed

+33
-0
lines changed
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
package leetcode
2+
3+
import (
4+
"github.com/halfrost/LeetCode-Go/structures"
5+
)
6+
7+
// TreeNode define
8+
type TreeNode = structures.TreeNode
9+
10+
/**
11+
* Definition for a binary tree node.
12+
* type TreeNode struct {
13+
* Val int
14+
* Left *TreeNode
15+
* Right *TreeNode
16+
* }
17+
*/
18+
19+
func mergeTrees(root1 *TreeNode, root2 *TreeNode) *TreeNode {
20+
if root1 == nil {
21+
return root2
22+
}
23+
24+
if root2 == nil {
25+
return root1
26+
}
27+
28+
root1.Val += root2.Val
29+
root1.Left = mergeTrees(root1.Left, root2.Left)
30+
root1.Right = mergeTrees(root1.Right, root2.Right)
31+
32+
return root1
33+
}

0 commit comments

Comments
 (0)