13ms swift solution


  • 0
    S
    func mergeTrees(_ t1: TreeNode?, _ t2: TreeNode?) -> TreeNode? {
      if(t1 == nil || t2 == nil){
            return t1==nil ? t2 : t1
        }
        let result = TreeNode.init(t1!.val + t2!.val)
        result.left = mergeTrees(t1?.left, t2?.left)
        result.right = mergeTrees(t1?.right, t2?.right)
        return result
    }

Log in to reply
 

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