File tree 2 files changed +43
-2
lines changed
solution/0600-0699/0617.Merge Two Binary Trees
2 files changed +43
-2
lines changed Original file line number Diff line number Diff line change 51
51
52
52
```
53
53
54
- ### ** ...**
55
- ```
54
+ ### ** Go**
55
+ ``` go
56
+ /* *
57
+ * Definition for a binary tree node.
58
+ * type TreeNode struct {
59
+ * Val int
60
+ * Left *TreeNode
61
+ * Right *TreeNode
62
+ * }
63
+ */
64
+ func mergeTrees (t1 *TreeNode , t2 *TreeNode ) *TreeNode {
65
+ if t1 == nil {
66
+ return t2
67
+ }
68
+ if t2 == nil {
69
+ return t1
70
+ }
71
+ t1.Val += t2.Val
72
+ t1.Left = mergeTrees (t1.Left , t2.Left )
73
+ t1.Right = mergeTrees (t1.Right , t2.Right )
74
+ return t1
75
+ }
76
+
56
77
57
78
```
58
79
Original file line number Diff line number Diff line change
1
+ /**
2
+ * Definition for a binary tree node.
3
+ * type TreeNode struct {
4
+ * Val int
5
+ * Left *TreeNode
6
+ * Right *TreeNode
7
+ * }
8
+ */
9
+ func mergeTrees (t1 * TreeNode , t2 * TreeNode ) * TreeNode {
10
+ if t1 == nil {
11
+ return t2
12
+ }
13
+ if t2 == nil {
14
+ return t1
15
+ }
16
+ t1 .Val += t2 .Val
17
+ t1 .Left = mergeTrees (t1 .Left , t2 .Left )
18
+ t1 .Right = mergeTrees (t1 .Right , t2 .Right )
19
+ return t1
20
+ }
You can’t perform that action at this time.
0 commit comments