mirror of
https://github.com/halfrost/LeetCode-Go.git
synced 2025-07-05 00:25:22 +08:00
Added solution 617
This commit is contained in:
@ -0,0 +1,33 @@
|
|||||||
|
package leetcode
|
||||||
|
|
||||||
|
import (
|
||||||
|
"github.com/halfrost/LeetCode-Go/structures"
|
||||||
|
)
|
||||||
|
|
||||||
|
// TreeNode define
|
||||||
|
type TreeNode = structures.TreeNode
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 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 {
|
||||||
|
return root2
|
||||||
|
}
|
||||||
|
|
||||||
|
if root2 == nil {
|
||||||
|
return root1
|
||||||
|
}
|
||||||
|
|
||||||
|
root1.Val += root2.Val
|
||||||
|
root1.Left = mergeTrees(root1.Left, root2.Left)
|
||||||
|
root1.Right = mergeTrees(root1.Right, root2.Right)
|
||||||
|
|
||||||
|
return root1
|
||||||
|
}
|
Reference in New Issue
Block a user