Skip to content

Commit 969b3b8

Browse files
committed
feature: add go solution for leetcode 0617
1 parent 673ce85 commit 969b3b8

File tree

2 files changed

+43
-2
lines changed

2 files changed

+43
-2
lines changed

solution/0600-0699/0617.Merge Two Binary Trees/README.md

+23-2
Original file line numberDiff line numberDiff line change
@@ -51,8 +51,29 @@
5151

5252
```
5353

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+
5677

5778
```
5879

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
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+
}

0 commit comments

Comments
 (0)