We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 578c85e commit 21c05dfCopy full SHA for 21c05df
leetcode/0617.Merge-Two-Binary-Trees/617. Merge Two Binary Trees.go
@@ -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
33
+}
0 commit comments