Simple and clean 7 lines in Go


  • 0
    M
    func mergeTrees(t1 *TreeNode, t2 *TreeNode) *TreeNode {
        if t1 == nil {
            return t2
        }
        if t2 == nil {
            return t1
        }
        
        return &TreeNode{t1.Val+t2.Val, mergeTrees(t1.Left, t2.Left), mergeTrees(t1.Right, t2.Right)}
    }
    

Log in to reply
 

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.