ruby solution


  • 1
    S

    add a ruby solution since there aren't many

    def merge_trees(t1, t2)
        result = TreeNode.new(0)
        if (t1 || t2).nil?
          result = nil
        elsif (t1 && t2).nil?
          result = t1 || t2
        else
          result.val = t1.val + t2.val
          result.left = merge_trees t1.left, t2.left
          result.right = merge_trees t1.right, t2.right
          result
        end
    end
    

Log in to reply
 

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