Skip to content

Commit

Permalink
add LC-617
Browse files Browse the repository at this point in the history
Signed-off-by: Tahsin Tunan <[email protected]>
  • Loading branch information
tahsintunan committed Dec 28, 2022
1 parent ee7a3bc commit 8f7df24
Showing 1 changed file with 26 additions and 0 deletions.
26 changes: 26 additions & 0 deletions go/0617-merge-two-binary-trees.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
/**
* Definition for a binary tree node.
* type TreeNode struct {
* Val int
* Left *TreeNode
* Right *TreeNode
* }
*/
func mergeTrees(root1 *TreeNode, root2 *TreeNode) *TreeNode {
if root1 == nil && root2 == nil {
return nil
}
if root1 == nil {
return root2
}
if root2 == nil {
return root1
}

var node TreeNode
node.Val = root1.Val + root2.Val
node.Left = mergeTrees(root1.Left, root2.Left)
node.Right = mergeTrees(root1.Right, root2.Right)

return &node
}

0 comments on commit 8f7df24

Please sign in to comment.